Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

10.4.2. Functions // Default Value

/*This example modifies the hello function to use a default value for 
name. If name is not defined when hello is called, it will use the 
default value.*/

function hello(name = "World") {
   return `Hello, ${name}!`;
}

console.log(hello());
console.log(hello("Lamar"));

//Hello, World!
//Hello, Lamar!
Source by education.launchcode.org #
 
PREVIOUS NEXT
Tagged: #Functions #Default #Value
ADD COMMENT
Topic
Name
9+1 =