Transcript from the "Values & Data Types Exercise" Lesson
>> Let us poke around with some values, shall we? You can use the typeof operator to figure out what these values are. And what I'm going to ask you'll to do, is before you type anything in, guess, what type of value of the ones that we've seen so far, are each of these values.
[00:00:25] So we're gonna take a moment to think about it to ourselves and then use our typeof friend to check our answers and then we'll talk through it together. Okay, so let's see. How do we feel about these values? Were we able to guess them? Sometimes, I would imagine at least one would have been very difficult to guess.
[00:00:51] Okay, so let's see. False, what type is it?
>> Boolean, exactly. It is the counterpart to true. We already discussed these are with no quotes around them. These are Boolean values, and they're the only ones. How about the second one in quotes, true? We already looked at it a minute ago, this is a, Stephen?
>> A string, exactly. So we looked at this a second ago, I think I probably still have it in my history here, yeah. So typeof in quotes, true string. That's again different than if we do typeof just the word true. Okay, how about document.title? What did we get?
[00:01:34] It's also a?
>> String, yes. So document.title, again, we said that it's gonna be, well, in this case it's new tab because I'm not even in a document. But if we typeof that, We expect some kind of title, some kind of text to describe this page or name this page.
[00:01:58] How about though, if we take a string like some string, and then we do .length. What did this come back with? What type of value does this come back with?
>> Number, so remember the .length we said, we ran into it earlier, it tells us on certain types of things.
[00:02:17] It tells us how many things are in this thing. So we use it earlier to find out how many children are in a certain element, or sort of the children of a certain element in our HTML document. We can also use it on strings, and we're gonna look at this in a second.
>> Why is typeof undefined coming out as in quotes undefined?
>> Haha, so this is a great question. So for example, when I do typeof 42 I get number. Why do I when I do typeof a in quotes 42, I get string in quotes? So typeof, if we look it up, In our MDN friend, we can type in typeof and go to the page, this is the definition of the typeof, it's an operator.
[00:06:18] We're gonna talk about what operators are a little bit later. But the typeof operator essentially always returns a string. And the string corresponds to the name of the type that this thing is. So, types themselves are identified by these strings that indicate one of these several values. So string number, string, string, string, Boolean, etc.