/* No value is assigned to the variable. */
let x;
console.log(x); // Returns undefined to indicate that the variable has not been assigned a value.

/* Represents that the variable
   explicitly or intentionally has no value. */
let y = null;
console.log(y); // null
let x; // undefined value
console.log(typeof x); // "undefined"

let y = null; // null value
console.log(typeof y); // "object"
/* Variable x with an undefined value */
let x;

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

// Evaluate using the Boolean() function.
console.log(Boolean(x)); // false

/* Variable y with a null value */
let y = null;

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

// Evaluate using the Boolean() function.
console.log(Boolean(y)); // false
let x = undefined;
let x = null;
/* Function that checks whether a value has been assigned to a variable */
let validationVar = (v) => {
    if (v === undefined) {
        return "No value has been assigned to the variable.";
    }
    return v;
};

let x;

console.log(validationVar(x)); // Output: "No value has been assigned to the variable."

Mainly used in APIs,
the null value is used as the value returned when an object is expected but no related object actually exists.

<!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>
/* Variable x with a value of undefined */
let x;

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

/* Undeclared variable */
if (y === undefined) { // Uncaught ReferenceError: y is not defined

}
/* Variable x with a value of undefined */
let x;

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

/* Undeclared variable */
if (typeof y === "undefined") {
    console.log("Evaluates to true.");
} else {
    console.log("Evaluates to false.");
}
// Output: "Evaluates to true."
/* Variable x without an assigned value */
let x;

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

/* Undeclared variable y */
try {
    y; // Attempt to access the variable
    console.log("The variable has been declared.");

} catch (error) {
    console.log("The variable has not been declared.");
}
// Output: "The variable has not been declared."
/* 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."