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
Post a Comment