Null vs Undefined - Beau teaches JavaScript

preview_player
Показать описание
Learn about the difference between null and undefined in JavaScript.

Code:

Other resources on topic:

⭐JavaScript Playlists⭐
-
We're busy people who learn to code, then practice by building projects for nonprofits. Learn Full-stack JavaScript, build a portfolio, and get great references with our open source community.

Рекомендации по теме
Комментарии
Автор

So, the best way to understand "null" vs "undefined" is – Imagine you are on an online store and you see a t-shirt, you click on it and you are taken to the customize page. So, by default the color of the t-shirt is red, but you as developer want your customers to have "none" as default color so you will set the value of your variable to "null" in your code. This example can also be found in photo-editing softwares like "Photoshop" where you can select the color as none. "Null" clears the value of your variable and is only used by developers when you explicitly want to clear the value of a variable.


"Undefined" is slightly different, it does not clear the value of the variable. It means you have simply not declared a value to your variable, and the first color available for t-shirt will be selected as the default color.


Hope it helps!

drrragonfly
Автор

But, no exact explanation. Why do we have both. What is the purpose of keeping both the types?

vickyvikash
Автор

Sorry but this is more confusing than it is clarifying. The first explanation was fine, ie "undefined is a variable which has no value assigned to it yet". So far, so good. But it only goes downhill from there in my opinion. Console-logging I can do at home, what I need is to understand the concepts behind...

manifestdigitalagency
Автор

Thanks again Beau, I just started coding probably two weeks ago and came into some real trouble trying to figure out, functions, functions expressions, comparison operators etc. These videos are really well made and actually go through what is going on in the code itself. Good job!

jamesbettess
Автор

Thanks this is good! Great and clear clarifications on the differences.

ChrisTian-oxnr
Автор

thanks for the explanation, it was clear and concise.

kiwi-Centaur
Автор

So the "null" is like the number 0 for string type, but "undefined" means that you have nothing in the variable. So can assign "null" to a variable. "undefined" exists when you declare a variable but have not assigned any value to it.

thanhnhannguyen
Автор

this was very confusing to me at first, but now I seem to understand it better thanks to your video.
So, in other words, "null" is an empty value, such as a zero, that can be assigned to a variable. Meanwhile, "undefined" is a value that has not been assigned to no variable. Please feel free to correct me if I am wrong in my interpretation.

ashleyr
Автор

Thanks for this! Interesting stuff. Shame others dont appreciate

Cactuspractice
Автор

This video introduce that !!null is false which is make no any sense for some people learning Javascript for the first time. I think you should also introduce the concept of 'Truthy' and 'Falsy' in Javascript. I think it is important.

JundiAhmadAlwan
Автор

I have noticed Beu explains great for html, and css but Javascript....not so much if anything alot of times I get more confused as a newbie self taught developer

jaysterable
Автор

null is an object used as a number and NaN is a number that cant be used as a number . this is what i find hard to accept xD

martinXDDK
Автор

One of best explanation I've heard on #null vs. #undefined in #JavaScript. Lot of hands-on #examples. Thank you!

heggyhere
Автор

does null and undefined means the same in java and JavaScript?

bhaskarsingh
Автор

Well, I have no words for you, seriously! While watching your video lessons, I feel like I'm reeeeally learning how to code, in a deep way. Before finding you, I was literally lost and couldn't understanding anything at all. THANK YOU SO MUCH, YOU'RE

SupportCodyS
Автор

Identity vs Equality operators between null & undefined.

sobeidalagrange
Автор

My biggest subtle takeaway from this was...
-undefined: either the programmer or the Javascript engine can assign a variable/property with this value
-null: a value ONLY a programmer can program a variable/key/etc to have. the computer will never assign something on its own with a value of null. it's something programmed in and an expected, *intentional* value.

I'm sure this info will come in handy debugging in the future. Thanks!

JenTran
Автор

That is one loud ass keyboard youre using hahahahaha

meinsouza
Автор

Idk why this video is prepared in rush, and the information is piled up.

abie
Автор

so basically null means zero and undefined means that no value is defined.

bhaskarsingh