Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is due to the character <code>3</code>'s <a href="http://en.wikipedia.org/wiki/ASCII" rel="nofollow">ASCII</a> value (ASCII is a widely-used way for computers to numerically represent various common characters). If you look under the <a href="http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters" rel="nofollow">ASCII printable characters</a> section of that Wikipedia article, you'll see that the <strong>Glyph</strong> (or character) <code>3</code> has a <strong>Dec</strong> value of <code>51</code>. You can see the dec values of other common printable characters in that same table.</p> <p>Remember that when you press the <kbd>3</kbd> key on your keyboard, the computer is going to see the <em>character</em> <code>3</code>, and not a raw <em>integer</em> value of <code>3</code>. The Glyph column of that table represents the character value, and the Dec column represents the raw integer value representing that character in the ASCII scheme. You can also see the Binary representation in that table, which is what the Dec integer value breaks down to for how a computer actually handles that value on the lowest level.</p> <p>In your code, the <code>charCode</code> variable is being assigned the <em>dec</em> value of the keystroke (via <code>e.which</code> or <code>e.keyCode</code>, where <code>e</code> looks to be the base JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event" rel="nofollow"><code>Event</code> object</a>), which is of type <code>Number</code>. This is why the <code>switch</code> further down in the code is comparing <code>charCode</code> against numerical values.</p> <p>You can switch between characters and their dec values in JavaScript with the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode" rel="nofollow"><code>fromCharCode()</code></a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt?redirectlocale=en-US&amp;redirectslug=JavaScript/Reference/Global_Objects/String/charCodeAt" rel="nofollow"><code>charCodeAt()</code></a> functions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload