Join Eve Porcello for an in-depth discussion in this video Default function parameters, part of Up and Running with 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.