javascript - JS if not a variable -
this question has answer here:
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
Post a Comment