0

What is the difference between null and undefined

In javascript what is the difference between null and undefined

31st Jul 2022, 12:59 AM
Semilore
Semilore - avatar
3 ответов
+ 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)
31st Jul 2022, 2:32 AM
Chris Coder
Chris Coder - avatar
+ 1
Chris Coder Thank you so much for the help
31st Jul 2022, 2:35 AM
Semilore
Semilore - avatar
0
Prince Semilore You are welcome
31st Jul 2022, 2:36 AM
Chris Coder
Chris Coder - avatar