javascriptcharacter-encodingbase36fromcharcode

String.charCodeAt Max Length


Take this code:

var charCode = unkownVariable.charCodeAt(0);

What is the max length that charCode can be? All my tests turned out as 2 character (2 digits). Will it ever be longer?


Solution

  • From the specification:

    Returns a Number (a nonnegative integer less than 216) representing the code unit value of the character at position pos in the String resulting from converting this object to a String. If there is no character at that position, the result is NaN.

    So, 216 - 1 is the maximum value, which is 65535.