Default Parameters
It is used to give the default values to the arguments, if no parameter is provided in the function call.
Syntax:
function fnName(param1 = defaultValue1, ..., paramN = defaultValueN) {
. . .
}
Example: In the below example, the first function gives result 7 whereas the second function call will be “undefined” as we did not pass any second argument.
Javascript
function add(a, b) { return a + b } console.log(add(5, 2)); // 7 console.log(add(5)); // NaN |
Output
7 NaN
JS 2015 or ECMAScript 6 (ES6)
JS 2015 (ES6) also known as ECMAScript 6 (ES6), ECMAScript 6 (ES6) is a significant update to JavaScript, introducing arrow functions, classes, template literals, let and const for variable declaration, enhanced object literals, destructuring, and more modern features for better code organization and readability.
Contact Us