Q:

javascript optional parameters

const myFunction = (str, id=0) => {
	console.log(str, id)
} 
myFunction("Hello Grepper")
// OUTPUT : "Hello Grepper 0"

myFunction("HG", 10)
// OUTPUT : "HG 10"
1
let variableToSet = checkedValue || defaultValue;
1
function func(arg, optArg = "defualtValue") {
  console.log(arg, optArg);
}

func("A", "B"); //output "A", "B"
func("Test"); //output "Test", "defaultValue"
func(); //output undefined, "defualtValue"
0

New to Communities?

Join the community