Question:

Describe at least 4 properties on the keyboard event object and explain what they are used for.


I will discuss four key event properties. They are key , code, location and the metaKey.

  • key

The key property returns a string of the value you pressed. If you press the ‘a’ key it will return a.

See the Pen key by oscar (@nopity) on CodePen.

  • code

The code property returns a string for what key was pressed it’s a bit more specific in terms of what it will return.

See the Pen code by oscar (@nopity) on CodePen.

  • location

location will return a number based on what area the key in on your input device.

See the Pen location by oscar (@nopity) on CodePen.

  • metaKey

The metaKey is used to represent the command key on macs or the windows key on windows. We can use this property when we want to have the user press command and another key.

See the Pen metakey by oscar (@nopity) on CodePen.