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 trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

Igor Yamshchykov
Igor Yamshchykov
24,397 Points

Null 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

null 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.

1 Answer

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Yea 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.