javascript - JS if not a variable -


so want write function takes 3 parameters, 3rd 1 being optional. want check if optional not exist give default value. there if not way of doing it? if not whats best way of doing it?

this want

foo.(x,y, opt){ if (!opt){opt = 1;} ...... ......  } 

this have:

foo.(x,y, opt){ if (opt){} else {opt = 1;}; ...... ......  } 

if parameter not passed function, it's undefined.

function foo( x, y, opt ){     if( typeof opt === 'undefined' ){          opt = 1;     }     ... } 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -