Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Named Parameters

function example({ arg1 = 1, arg2 = 2, arg3 = 3 } = {}) {
  return { arg1, arg2, arg3 };
}

function problem({failure = true}) {
  return failure;
}

problem(); //TypeError: Cannot read property 'failure' of undefined

example({ arg2: 4, arg1: 2 }); // { arg1: 2, arg2: 4, arg3: 3 }

example(); // { arg1: 1, arg2: 2, arg3: 3 }
Source by masteringjs.io #
 
PREVIOUS NEXT
Tagged: #Named #Parameters
ADD COMMENT
Topic
Name
9+4 =