JavaScript Learning Notes: Arrays


                    const userEmail = []

                    if (userEmail) {
                        console.log("Got user email");
                    } else {
                        console.log("Don't have user email");
                    }
                

Console Output:
Got user email

Falsy Values

false, 0, -0, BigInt 0n, "", null, undefined, NaN

Truthy Values

"0", 'false', " ", [], {}, function(){}



                    const userEmail = []
                    if (userEmail.length === 0) {
                        console.log("Array is empty");
                    }
                    
                

Console Output:
Array is empty



                    const emptyObj = {}

                    if (Object.keys(emptyObj).length === 0) {
                        console.log("Object is empty");
                    }
                

Checking object is empty or not

Console Output:
Object is empty



                    // Nullish Coalescing Operator (??): null undefined

let val1;
val1 = 5 ?? 10
val1 = null ?? 10
val1 = undefined ?? 15
val1 = null ?? 10 ?? 20
console.log(val1);

                

Checking object is empty or not

Console Output:
10



                    // Terniary Operator

// condition ? true : false

const iceTeaPrice = 100
iceTeaPrice <= 80 ? console.log("less than 80") : console.log("more than 80")
                

Checking object is empty or not

Console Output:
more than 80