<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>null Value</title>
    </head>
    <body>
        <h1>null Value</h1>
        <p>
            In APIs, an object is expected to be returned, but 
            when no related object actually exists, 
            a null value is returned.
        </p>
        <script>
            const ele = document.querySelector(".get-class");

            /* If no element with the class name "get-class"
               exists in the HTML document,
               null is returned. */
            console.log(ele); // Output: null
        </script>
    </body>
</html>
let x = null;
console.log(typeof x); // "object"
let x = null;

if (x === null) {
    console.log("The variable is null.");
} else {
    console.log("The variable is not null.");
}
// Output: "The variable is null."
let x = null;

if (x) {
    console.log("Evaluates to true.");
} else {
    console.log("Evaluates to false.");
}
// Output: "Evaluates to false."

// Evaluation using the Boolean() function
console.log(Boolean(x)); // false
/* A variable with a null value */
let x = null;

if (x === null) {
    console.log("Evaluates to true.");
} else {
    console.log("Evaluates to false.");
}
// Output: "Evaluates to true."

/* An undeclared variable y */
if (y === null) { // Uncaught ReferenceError: y is not defined
    
}
/* A variable with a null value */
let x = null;

if (x === null) {
    console.log("The variable is null.");
} else {
    console.log("The variable is not null.");
}
// Output: "The variable is null."

/* Check whether a variable is declared */
if (typeof y !== "undefined") {
    // Check whether the variable is null
    if (y === null) {
        console.log("The variable is null.");
    } else {
        console.log("The variable is not null.");
    }
} else {
    console.log("The variable is not declared.");
}
// Output: "The variable is not declared."
/* A variable declared but not assigned a value */
let x;
console.log(x); // undefined is returned because no value has been assigned

/* A value explicitly set by the developer to indicate the absence of a value */
let y = null;
console.log(y); // null
typeof null; // "object"
typeof undefined; // "undefined"

null == undefined // true
null === undefined // false
let x; // undefined
let x = null;