The other answers here are good, but, if you're using a lot of commands targeting the same entity, or something like that, you may want to use tags.
For example, let's say that we have the following commands:
execute at @e[type=arrow,nbt={inGround:1b}] run summon tnt
execute as @e[type=arrow,nbt={inGround:1b}] run kill @s
This sounds good, right? It will hit the ground, explode once, then kill itself.But, the thing is, this won't always work. If the block the arrow is in is destroyed, the arrow is no longer inGround:1b
, so it won't kill itself. Instead it will be bounced into the sky by the explosion, and continue exploding and bouncing.
Instead, tag your entity. Tags are useful for a number of things, but, here's a working version of the explosive arrow command.
execute as @e[type=arrow,nbt={inGround:1b}] run tag @s ArrowThatExplodes
execute at @e[tag=ArrowThatExplodes] run summon tnt
kill @e[tag=ArrowThatExplodes]
Now what will happen is, the arrow will be detected in the ground. It will summon a tnt, and instead of detecting again for an arrow in the ground, it instead targets the same arrow and kills it.
With your lightning use case, you don't really need this, although it may hep with lessening the amount you have to type. I imagine it will also improve performance, though I haven't tested it.