r/badcode • • Aug 06 '21

js How to create a virtual keyboard

Post image
888 Upvotes

43 comments sorted by

View all comments

Show parent comment

1

u/kelub Aug 06 '21

Const would work but let would be preferred IMO. (Const is typically for non-changing values, but both are preferred to var to control the scope.)

Either way, with the scope limited to the function, "return element" would need to be added at the end so the function call provides the value.

1

u/_default_username Aug 08 '21

The variable is always referencing the same HTML element, so const is quite appropriate to use.