I have JavaScript like this:
var myParam = 1;
var myVar = 'Lorem ipsum dolor [placeholder] amet';
I need to check, if myParam will be 1 then put inline of myVar - one else put there two. Something like this:
var myParam = 1;
var myVar = 'Lorem ipsum dolor '+ if (myParam == 1) return 'one' else return 'two' +' amet';
How to put IF/ELSE statement inside sting?
===instead of==. If you know the type (Number or String) you can safely use===.valuelike this:myVar = 'some text '+ (typeof Obj.value != 'undefined' ? Obj.value : 'N/A') +' another text';Which of these should I use!=or!==??typeofwill always return a string, and'undefined'is a string, so use!==. I have always claimed that there is never a valid reason to use==(or!=), if you know of one I'd love to hear about it :)