0
What is the difference between null and undefined
In javascript what is the difference between null and undefined
3 odpowiedzi
+ 3
An undefined variable is one that exists but has not been assigned a value. Which means that later, I can come back to my variable and give it a value that it did not have before.
Example:
let x;
console.log(x)
// undefined
x = 2; //x is now defined has value of 2
console.log(x)
// 2
Null is a value that you can assign to any variable if you want that variable to be empty. As you cannot leave the value blank (undefined), you must use null to point to an empty value.
Example:
let y = null
console.log(y)
// null (empty)
+ 1
Chris Coder Thank you so much for the help
0
Prince Semilore You are welcome