Answers for "javascript parameter default parameter"

16

javascript default parameters

function multiply(a, b = 1) {
  return a * b;
}
Posted by: Guest on April-08-2020
1

javascript parameter default parameter

function say(message='Hi') {
    console.log(message);
}
say(); // 'Hi'
say(undefined); // 'Hi'
say('Hello'); // 'Hello'


function date(d = today()) {
    console.log(d);
}
function today() {
    return (new Date()).toLocaleDateString("en-US");
}
date();


function add(x = 1, y = x, z = x + y) {
    return x + y + z;
}
console.log(add()); // 4
Posted by: Guest on May-18-2020
2

javascript default function parameter value

function multiply(a, b) {
  b = (typeof b !== 'undefined') ?  b : 1
  return a * b
}
Posted by: Guest on December-17-2020

Code answers related to "javascript parameter default parameter"

Code answers related to "Javascript"

Browse Popular Code Answers by Language