![]() ![]() But if I don't provide a value for name,Ġ1:56 we'll get undefined. ![]() If I provide a name like, I don't know, Tony, we get Hello Tony. Similarly, if I call a function without providing a value for an argument, like this very simple greet function, it expects a name. So if I try and access a property that doesn't exist like age, I get undefined.Ġ1:37 It's the lack or absence of a value here. So if I have some object like person, and let's just say our person only has a name. Undefined, as I've mentioned, represents the absence of a value.Ġ1:17 A really common place where you'll run into this is if you try and access a non-existent property on an object. But the default behavior is when you declare a variable with no value, you don't initialize it, it will be initialized to the value of undefined, which is a true value in JavaScript. Just so you know, it's still going to be undefined. It is the absence or the lack of a value.Ġ0:58 Now, I could explicitly set something to undefined too. If I don't, its default value is undefined. It's a value that represents the absence of a value or an uninitialized value.Ġ0:38 So it's the default value for any variables that we declare that do not have a value assigned, like let, I don't know, username. So undefined is a primitive value in JavaScript, just like Boolean values, true or false, or numbers, for example, and it's spelled undefined and all lowercase. Both of them sound like they have to do with nothingness, or negativity, or emptiness, or something like that.Ġ0:18 But let's start by talking about undefined. A lot of people mix them up when they're starting out with JavaScript. 00:00 In this video, we'll talk about two very important special data types in JavaScript, null and undefined, what they are and how they are similar and how they're different.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |