把這個代碼:使用String.charCodeAt最大長度
var charCode = unkownVariable.charCodeAt(0);
什麼是最大長度charCode
可以嗎?我所有的測試結果都是2個字符(2位數字)。它會更長嗎?
把這個代碼:使用String.charCodeAt最大長度
var charCode = unkownVariable.charCodeAt(0);
什麼是最大長度charCode
可以嗎?我所有的測試結果都是2個字符(2位數字)。它會更長嗎?
返回一個號碼(非負整數小於2 )代表字符的在
pos
位置從該對象轉換爲字符串產生的字符串的代碼單元值。如果在該位置沒有字符,則結果爲NaN
。
所以,2 - 1爲最大值,這是65535
。
簡答:是的。
var unkownVariable = 'test';
var charCode = unkownVariable.charCodeAt(0);
console.log(charCode); // 116
有用於顯示字符(有不同的語言和字符集來考慮)16位,所以響應理論上可以在任何地方65536 0至(2^16)。
MDN說
注意charCodeAt總是會返回一個值小於 65,536。
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/charCodeAt
有趣。因此,最高字符代碼的最小單字節表示(具有本地JS解碼支持)將爲:'1ekf'('(65535).toString(36)') – 2013-03-21 17:19:28