javascript tips - how to add object w/o the need to write a lot of ifs -


i have object has 3 parameters. in cases 1 of parameters can empty.

is there quick & clean coding doing below code w/o getting error if 1 of parameters doesn't exist.

var str = object.x &&  + object.y + object.z 

one clean , simple way add them be:

var str = (object.x || '') + (object.y || '') + (object.z || ''); 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -