NodeJS (최신).
다음 코드가 있습니다. 첫 번째 IF 문이 예상대로 작동하지 않는 이유는 무엇입니까? 컨트롤은 첫 번째 IF 문 안에 들어 가지 않습니다.
다음 코드의 첫 번째 줄에 유효한 console.log 출력이 표시되고 첫 번째 IF 문도 코드를 실행해야한다고 예상했습니다. 하지만 그렇지 않습니다. 두 번째 IF 문이 작동합니다.
console.log("-- inside create IP() qData['osType'] is set to :: " + qData['osType'])
//--
if ( qData['osType'] == 'undefined' ) {
console.log("1 -- setting qData['osType'] = Linux by default for now. This should happen automatically.")
qData['osType'] = 'Linux'
console.log("1 -- inside create IP() if-statement-qData['osType'] and qData['osType'] is set to :: "+qData['osType'])
}
if ( typeof qData['osType'] == 'undefined' ) {
console.log("2 -- setting qData['osType'] = Linux by default for now. This should happen automatically.")
qData['osType'] = 'Linux'
console.log("2 -- inside create IP() if-statement-qData['osType'] and qData['osType'] is set to :: "+qData['osType'])
}
qData['osType'] = 'Linux'
//--
정의되지 않았는지 확인하는 경우 다음 중 하나를 수행 할 수 있습니다.
typeof foo === 'undefined'
foo === undefined
foo === void 0
다른 것은 실제로 (엄격히) 정의되지 않은 값을 확인하지 않습니다 (값을 문자열과 직접 비교하는 것을 포함 'undefined'
).
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다