JavaScript Questions: What is the Best Way to Work with undefined?

preview_player
Показать описание
JavaScript has two methods for indicating the absence of value: null and undefined. In this video we examine the difference between null and undefined and we take a look at the best way to check to see if something is undefined.

For a complete list of all our tutorials:

Take the Learn Modern JavaScript: Getting Started or the Learn Modern JavaScript: Advanced Topics courses at a huge discount:
Рекомендации по теме
Комментарии
Автор

Nice! I liked the use of typeof operator to check whether a variable exists.
There is one thing I am a little confused about. You said that only the system assigns 'undefined' value, but I've seen that when you are trying to grab an element from the DOM, that does not exist, javascript returns 'null'. Is that somehow different or I'm missing something? Thanks for the videos!

aleksandregorov
Автор

Thanks for the video Sir.
I have got a question. In this below code, why I am getting an empty string in the console while I am expecting 100. Since empty string and undefined are falsy and they will evaluate to false(coerced before comparing)
var a = "";
if (a == undefined) {
a = 100
}
console.log(a);

I appreciate your answer

alibaghban
Автор

Thanks. Is there a particular reason why javascript requires a to be in quotes "a" when checking if variable is in window and otherwise simply use a without quotes? The quotes seem kind of strange to me as a beginner.

DanielWeikert
Автор

"a" in window is returning false for me. Did something change in js. since the video? I am using visual studio and the live server extension.

androidetube