Join Eve Porcello for an in-depth discussion in this video Default function parameters, part of Learning ECMAScript 6.
- One of the easiest to implement features…of ES6 is using default parameters in your functions.…Let's create a really basic function…to add two numbers together.…Here, on line six, I've created a function called add.…And add is going to take in x and y.…The add function will then console.log…x plus y.…Let's go ahead and call this function on line ten,…and I"m not going to pass in any arguments.…
Now if I run this, we'll see NaN, not a number,…as our result.…Let's try this again with default values.…On line six, I'm going to set x equal to five.…And I'm going to set y equal to seven.…Now, if I save and run this again,…we're going to see that the value is 12.…So not surprisingly, when I call this…without passing values,…the function will use the default values.…Let's give this a shot with a string value…in combination with one of those new template strings.…
Let's create a function called haveFun,…and we're going to pass in activityName…and time.…Now we want to console.log something…a little more exciting here.…We're going to pass in a string template.…
- What is ECMAScript?
- Transpiling ECMAScript with Babel and Babel-node
- Using the let and const keywords
- Creating strings with template strings
- Enhancing object literals
- Working with ES6 classes and class inheritance
Skill Level Beginner
Q: The Babel API is out of date. How do I proceed with the course?
A: We are updating the course. In the meantime, you can install the babel-cli package and then install the presets that you need to follow along with the tutorials.
1. What Is ECMAScript 6 (ES6)?
2. Transpiling ES6
3. ES6 Syntax
4. ES6 Functions & Objects
5. Asynchronous Features
6. ES6 Classes
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.