This course has been updated! We now recommend you take the Complete Intro to Web Development, v3 course.
Transcript from the "Builtins" Lesson
[00:00:16] For example, strings have a bunch of functions kind of built into it. So you don't have to write these yourself. So I have this string has weird casing in it, the Spongebob cases as we were alluding to previously. And then you can say, sentence.toLowerCase, right? I didn't write this toLowerCase, this is built into the string itself.
[00:00:58] It has just lower case. And just as you might imagine there is also toUpperCase if you can spell uppercase, right, and that works as well. An easy way to kind of explore this is one definitely check out the MDN that has very exhaustive everything for it. But I can also come down here to my DEV tools.
[00:01:24] Let me make that a little bit bigger for you. And then I have like some string. I can hit dot and it brings up this like pop up right here. And I can actually go through and see, it's like hey look it has a slice method. It has a startsWith method.
[00:01:40] It has a substring, blah blah blah, all those different things and you can just kind of explore right there. Same thing with code if we go over to our editor. If I come in her and say bla., this is actually built into VS code as well. VS code actually does do some, this is called type checking.
[00:02:03] So it's actually aware that this is a string. So it brings up everything that strings have on it, and that's a really, really cool feature of VS code. Again, check out Mike North's VS Code course on Frontend masters. It's really good. It goes through a lot of this stuff.
[00:02:39] I'm quite fascinated by them.
>> Brian Holt: See if I have any other, right. So like, there is a Math object. So, if I do Math.round, it is going to round that number to the nearest number, right? So, if I do Math.round(5.1), I get 5. That follows. There is also Math.floor, which means round down.
[00:03:07] So even if I put 5.99999, if I do Math.floor, guess what it does. It rounds all the way down to 5. And there's also ceil, C-E-I-L. I didn't write this, that's actually what it is. It means always round up. So if I do like
>> Brian Holt: 6.1, it's gonna round up to 7, right.
[00:03:33] So the Math object, as it's called, has a bunch of methods on it. Again, I can come in here to my Visual Studio Code and I can say Math., stop and it has everything on here. It does logarithms, it does powers, it does sine and cosine and stuff like that.
[00:03:55] So it's just an object full of all these different math methods for you. It's all in the MDN, but just be aware that those things exist. So if you start seeing things like that come out, you can assume they're a built-in of some sort. Again here I have name, name = "Brian Holt".
[00:04:15] I do name.substr, and the way that this one particularly works is, I'm saying please start from the sixth character. Actually it's the seventh character. It's the sixth index. So, zero, one, two, three, four, five, six, which means start here. Or you can see my cursor flashing. And then, it says grab three characters.
[00:04:44] So it's one, two, three, and then, you can see here, it's returning Hol. So if I do like 4, it's gonna do n H, right, because it grabs three characters. The space does count as a character. Or if I said 4, it would grab an additional character. Or if I just didn't give it a number, it would give me all the way to the end.
[00:05:12] So, that's what substr does. The reason why I don't call that substring is cuz there's actually one called substring that does something entirely different. [LAUGH] I don't actually remember, you end up using substring as much. I end up using this one more. But it's all in MDN, so if you're curious, check it out.
>> Brian Holt: And you can see I have indexToStart, howManyCharactersToInclude.
>> Brian Holt: There are a lot of these. So just Look at them in the MDN, I guess. And there's no reason you need to memorize them either. So