This course has been updated! We now recommend you take the TypeScript Fundamentals, v3 course.
Transcript from the "Primitive Types" Lesson
[00:00:00]
>> Mike North: With that, I wanna sort of set the stage and talk about JavaScript for a moment. Just so we know what we're starting with, because this TypeScript is a superset of JavaScript. We should know kinda what we're dealing with, at least as it pertains to typing and how types work.
[00:00:16] So we have a set of primitive values, we define primitive values as things that aren't objects. Things that don't have any methods, and we've got six primitive types. Five you're used to seeing and a new one that came with the 2015 version of the JavaScript language standard, it is called symbol.
[00:00:41] We'll learn a little bit about specific uses of symbol later. Just know that it is something where the name of the symbol is equal to its value. So, think of it like you can kinda treat them like strings. Imagine if it's like a string where variable name in this string the contents of the string had to match, right.
[00:01:05]
>> Mike North: Everything else in the language extends from Object, an array extends from Object, right. And that Object, we'll see later that that is sort of the basis for mutable values, everything else is immutable. So when necessary these primitive types are wrapped in a more rich object. And you'll recognize these richer objects because they start with a capital letter instead of the lower case letter.
[00:01:39] We can see the effect of this if we have something like this where we say the variable x has a value of JavaScript. And then we log out the type of x, and then we create a variable y, we use the string constructor here, right. Capital S, we're not witnessing autoboxing here, we're directly opting into the richer type via using the constructor.
[00:02:05] The output we'll end up seeing is this, right, so clearly these are not exactly the same. Now if we were to compare these two, they would be different in this case. So what we're gonna do is we can look at the fact that it's, that this idea of Carries over to Booleans as well.
[00:02:29]
>> Mike North: I showed this to you so you'd know the difference between lowercase s string, and uppercase S string. And the fact that we can say these have no methods, but they're sort of promoted automatically into things that have methods, like as soon as you need them. So most of the time this doesn't matter to us, but you just need to know that the primitive types, like a string, a number, a Boolean, these values are mutable.
[00:02:56] Meaning when we split a string, we are not mutating that string in place, we're creating new strings, right.
>> Mike North: Never, well I'm not gonna say never but it is nearly always incorrect to refer to the boxed variant of the primitive types. So when we start getting into things like type annotations, just make sure it gonna look for a lowercase s string.
[00:03:26] And call me out if you see something on the slides. I hope that I have wrestled the auto-capitalization of QNote back into submission. But just know the differences between those.