Created
August 13, 2021 20:05
What is the difference between null and undefined in JavaScript?
This file contains 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
null === undefined // false | |
null !== undefined // true | |
// Example | |
function PrintLog(str = 'Test') { | |
console.log(str); | |
} | |
PrintLog(); // Prints 'Test' | |
PrintLog("Hello World"); // Prints 'Hello World' | |
// But the surprise is here, | |
PrintLog(undefined); // Prints 'Test' | |
PrintLog(null); // Prints 'null' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment