

Below are some of the examples where they could be used: The premise of true or false conditions has been used in JavaScript executions for a long time.

Real Time Example: If we want to multiply 2 numbers through function but while calling if we pass only one number than we go result as NaN because we have passed only one value and second value automatically undefined so number*undefined becomes NaN (Not a Number).There's virtually an infinite number of cases in programming where you are required to execute tasks based on certain conditions. Previously this default value is used to test parameter values in the function body and assigned any value if they are undefined. Anyway as we have development scope we can set any value to this function parameter. If it is function parameter then the default value is "undefined". JavaScript default values are said to be values which are assigned by JavaScript compiler. Introduction on Default Value in JavaScript Given below are the examples mentioned: Example #1 Its working is based on required values and values to be assigned through the function. Let suppose function expects 5 parameters but if we assign only 3 then rest of the values assigned by JavaScript compiler that is undefined.įunctionName(1,2,3) // NaN Examples of JavaScript Default Value Web development, programming languages, Software testing & others How does Default Value work in JavaScript?
