Created
April 20, 2024 08:31
-
-
Save daanta-real/d5808e0252a2a2a95284b900c9035414 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a1; | |
var a2 = []; | |
var a3 = {}; | |
var a4 = {x:undefined}; | |
var a5 = {x:'1'}; | |
console.log("a1:", a1?.x || 'error'); | |
console.log("a2:", a2?.x || 'error'); | |
console.log("a3:", a3?.x || 'error'); | |
console.log("a4:", a4?.x || 'error'); | |
console.log("a5:", a5?.x || 'error'); | |
> a1: error | |
> a2: error | |
> a3: error | |
> a4: error | |
> a5: 1 | |
var aa = false ?? "난 선택될일이 없어요"; // ??은 null이랑 undefined만 검사함 | |
console.log(aa); | |
> false | |
var ss = false || "여긴 내가 나올것이야"; // ||은 null, 0, "", false, undefined 같은 falsy 값을 전부 검사함 | |
console.log(ss); | |
> 여긴 내가 나올것이야 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment