Today I Learned (2024.01.19)

다율·2024년 1월 19일

TIL

목록 보기
8/23
post-thumbnail

typeof

: 객체의 데이터 타입을 확인할 때 쓰는 연산자이자 함수

console.log('edward', typeof 'edward');
console.log('10', typeof 10);
console.log('3.14', typeof 3.14);
console.log('true', typeof true);
console.log('mybox', typeof mybox);
console.log('null', typeof null);
console.log('nudefined', typeof undefined);
console.log('[1, 2, 3]', typeof [1, 2, 3]);

/* 실행결과
edward string
10 number
3.14 number
true boolean
mybox undefined (변수에 값이 할당되지 않음을 뜻함)
null object
nudefined undefined	(변수에 값이 할당되지 않음을 뜻함)
[1, 2, 3] object*/

isNaN()

: 괄호 안의 값이 숫자이면 false, 숫자가 아니면 true를 return

console.log(1/0);		  // Infinity (무한대를 뜻함)
console.log('홍길동' * 3);	// NaN (숫자가 아님을 뜻함
console.log(isNaN(3));	  // false
console.log(isNaN('3'));  // false
console.log(isNan('홍길동'));	// true

exam1 (==, ===)

var myBox;
var yourBox = null;

console.log(myBox, typeof myBox);
console.log(yourBox, typeof yourBox);

console.log('==', null == undefined);
console.log('===', null === undefined);

/*undefined 'undefined'
null 'object'
== true
=== false*/

exam2

var myBox = '';
var yourBox = '  ';

console.log(myBox == yourBox);				// false
console.log(typeof myBox, typeof yourBox);	// string string


깃허브 링크

https://github.com/dayul/Javascript_Study

profile
새싹 개발자 🌱

0개의 댓글