Drecker
Drecker

Reputation: 1265

charCodeAt generates wrong code for comma

Why does code:

','.charCodeAt(0);

generates 44 even though charcode for comma is 188 (both by this table and when getting event.keyCode in keyup handler).

Upvotes: 2

Views: 796

Answers (1)

gre_gor
gre_gor

Reputation: 6804

Characters and keys are different things.

charCodeAt returns the numeric Unicode value of the character.
keyCode from the KeyboardEvent represents a key on a keyboard.

Since there is no 1:1 mapping between characters and keys, they don't necessarily use the same values.

Upvotes: 2

Related Questions