Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 90,705 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.