Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialIgor Yamshchykov
24,397 PointsNull and undefined difference?
What is actual difference between null and undefined ? When do both of them appear, and what are the special cases when they appear? What is appropriate use ? should I assign null to a variable that I want to be null or undefined ? And Why ? Would actually appreciate some article about it. Thank you
Igor Yamshchykov
24,397 PointsThank you a lot !
1 Answer
Jonathan Grieve
Treehouse Moderator 91,253 PointsYea Mithun was right.
Null is an empty value, like an array index referencing a key that doesn't exist or has nothing in it.
Undefined is a variable that has been referenced but doesn't actually exist.
Mithun B
Courses Plus Student 748 PointsMithun B
Courses Plus Student 748 Pointsnull is empty. It has no value and it is also not a string, variable, array or an object.
Undefined is a something that we forgot to define. Like if you forgot to assign 'function' to 'function crossCut(){}', crossCut will be undefined. JavaScript is not able to figure out if you created function or not.
I don't know if this is right. I tried my best with what I know.
Hope this helps.