This course has been updated! We now recommend you take the JavaScript: From First Steps to Professional course.
Transcript from the "Underscore.js Introduction" Lesson
[00:00:00]
>> [MUSIC]
[00:00:04]
>> Bianca Gandolfo: So now we're finally to the point where we can talk about Underscore. So we talked scope, we talked about how closures worked. We talked about the complexities between parameter versus an argument and how all these components work together and now we can use the utility library like Underscore js which combines all these concepts into a handy library that gives us all the utility functions that allows us to do some pretty cool things.
[00:00:35] So first thing is, has anyone used the library here? Raise your hand if you've used a library before. Cool, so underscore is just a library. Which basically a library, in a sense, is just a collection of methods available to you. So we have a jQuery library which provides us a function, a jQuery function that looks like this.
[00:01:03] And we can call it like that. Underscore is a library that gives us an object that's an underscore with a bunch of different properties on it. So the syntax for underscore, you'll see an underscore and a dot. And you can just imagine that somewhere in the library it says var_ = some object.
[00:01:26] And that's why we used .notation. And then we can say, _. Some method = some function. And then, some function that does something. So that's how it's working at it's core and we just include that JavaScript file in our HTML, we have access to all those methods and let's just check out the underscore library just to kinda get a feel of what it looks like.
[00:01:54] So this is just their documentation, you can see that, that underscore comes with all of these handy functions that you can use that make your code easier. The cool thing about underscore is it works in all environments, it's just pure JavaScript, it's not like jQuery where it only works in the browser.
[00:02:13] So you could use underscore, for example, in node it's used a lot. Or if you're doing some hardware stuff as well. Cool.
>> Bianca Gandolfo: And then, you can also look at the annotated source code which is really interesting. You can see like how they actually write underscore and it's all annotated so you could see like how reduce is written here, and, let's see, at the very bottom.
[00:02:49]
>> Bianca Gandolfo: So that's really handy, if you're getting stuck and you kinda wanna see how it's really working underneath. Yup?
>> Speaker 2: Did you say jQuery only works in the browser?
>> Bianca Gandolfo: Yes.
>> Bianca Gandolfo: If you think about it, jQuery's all about selecting DOM nodes and then manipulating them and then putting them back into the DOM.
[00:03:10] The DOM is lives in the browser. Cool. So we're gonna talk about a couple of underscore methods. How to use them, and then I'm kinda gonna set you use and let you just explore and work with underscore on some exercises.