There are twelve different values the
nodeName property can return, including
You can find the full list in the MDN Web Docs.
tagName property only works on a
Node that is also an
If you try to access it on a different type of node, you'll see
undefined. If it isn't an HTML element, it doesn't have a tag name.
If you want to test this, first highlight an HTML element in the inspector. Then access it in the console using the
$0 shorthand. Try accessing its
tagName properties like so:
Then do the same thing with an HTML comment and notice the difference.
tagName properties might have the same value, but this is purely coincidental.
I usually default to the
tagName property unless I specifically need to check something that isn't an HTML element.