변수의 타입
<script>
console.log(`typeof(5): ${typeof(5)}`); //number
console.log(`typeof(5.5): ${typeof(5.5)}`); //number
console.log(`typeof('5'): ${typeof('5')}`); //string
console.log(`typeof('nakwon'): ${typeof('nakwon')}`);//string
console.log(`typeof(x): ${typeof(x)}`); //undefined
console.log(`typeof(undefinde): ${typeof(undefinde)}`); //undefined
console.log(`typeof([1,2,3,4]): ${typeof([1,2,3,4])}`); //object
console.log(`typeof({'one:'하나','two':'둘'}): ${typeof({one:'하나', two:'둘'})}`); //object
function js(){
return 0;
}
console.log(`typeof(js): ${typeof(js)}`); //function
console.log(`typeof('js' / 2): ${typeof('js' / 2)}`); //number
console.log(`typeof(js / 2): ${typeof(js / 2)}`); //number
console.log(js / 2) // NaN not a number
console.log(`typeof('1' + 1): ${typeof('1'+ 1)}`); //String
console.log('1' + 1); // 11 ,
//다른언어에서는 문자와 숫자를 더하면 에러가 나온다.
console.log(`typeof('nakwon'): ${typeof('nakwon' / 3)}`); //number
console.log('nakwon' / 3) // NaN not a number
console.log(`typeof(true): ${typeof(true)}`);
let test = null;
console.log(`typeof(test) : ${typeof(test)}`); //object
//object는 어떤 값을 가지고 있는 객체인데
//null이 정의 된 변수 test는 object가 나온다
//왜일까? 이것은 js가 인정한 오류이다.
//하지만 해당 오류는 호환성 유지를 위해 수정하지않고 있다.
</script>