Define value if weapon is unequiped

Hi there, I do have another problem.
I split the damage of a weapon from skills like this: a.atk - $gameActors.actor(1).weapons()[0].params[2]. So all what's left is the base damage - the damage of the weapon.
Unfortunelately there is a problem when a weapon isn't equiped, then I will get an error because the equiped weapons is "null" What I need is to define a value for an empty weapon slot. (I assume it needs to be 0)
I searched in the json files but I have no idea where too look.
Code:
a.atk - (a.weapons()[0] ? a.weapons()[0].params[2] : 0)

This would check if the actor has a weapon in slot 0, if he has then it returns the params[2], if not it returns 0. So when the actor has no weapon equipped this formula will be a.atk - 0.

More info on that ?-Operator here:
http://www.rpgmakercentral.com/topic/36290-damage-formulas-101-mv-edition/
Thanks for the answer, i will test if that works. But that adds another minor problem. The battle formula is getting ridiciolusly long. Is there a possiblity to set macros or something like that for such terms?
I have a plugin for Damage Formula Macros, you can find it here https://forums.rpgmakerweb.com/inde...-addons-newest-way_customfaceimageeval.78979/
Oooh, thats pretty cool! That's exactly what I searched for.
Thank you very much, you are awesome!

Original thread: https://forums.rpgmakerweb.com/threads/define-value-if-weapon-is-unequiped.82925/