Thursday 5 December 2019

javascript - JS if not a variable

so I want to write a function that takes 3 parameters, 3rd one being optional. I want something to check that if optional does not exist then give it a default value. IS there a IF Not way of doing it? if not then whats the best way of doing it?



This is what i want




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


This is what I have:




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

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...