11/12 Code Question


#1

$(document).ready(function() {
$(document).keydown(function(key) {
switch(parseInt(key.which,10)) {

Can someone explain what parseInt does? i tried reading about it, but it doesnt really help.

I get that key.which turns the keydown'd key into its keycode numerical value. I don't understand:

  • the purpose of the number 10
  • what does parseInt do (as it relates to this specific code) and what parameters does it take

Thanks.


#2

Hi Jaredb21,

MDN: parseInt()

The function takes a string argument and displays it as an integer of the base indicated by the radix, as in base 10, our common decimal number system.

key.which is a variable of the keyboard event object. It may be a string, or it may be number, but parseInt() ensures it is a number at this point.
- Via @mtf

Does that explain your first question for you?


#3

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.