Javascript13(응용JS_삼항연산자) feat.velopert

min seung moon·2021년 3월 6일
0

Javascript

목록 보기
15/23

1. 삼항연산자

  • 세개의 항으로 된 연산자
  • 조건 ? true : false;

2. Truthy

  • true 같은거
  • !null, !undefined, !0, !'', !NaN, !false, ![], !{}
  • 3, 'hello', ['array'], { name : 'a' }, true

3. Falsy

  • flase 같은거
  • null, undefined, 0, '', NaN, false, [], {}
  • !3, !'hello', !['array'], !{ name : 'a' }, !true

4. null checking

functionprint(person){
	if(person===undefined||person===null)
		return;
	else
	console.log(person.name);
}

//값이있으면정상적으로작동
constperson={
	name:'John'
};

//값이없어서return
constperson=null;

print(person);

//위에함수랑동일하게동작
functionprint(person){
	if(!person)
		return;
	else
		console.log(person.name);
}   
profile
아직까지는 코린이!

0개의 댓글