重要的, 需要记下来的

//0开头的8进制
console.log((0771).toString('10'))  //505 
console.log((''+0771).slice(1));  //05
//0x开头的16进制 
console.log((0XfFF).toString('10'));  //4095 
console.log((''+0XfFF).slice(1));  //095 
//_(:3」∠)_ 暂时就上面两种特殊了 
console.log((0779).toString('10'))  //779 
console.log((''+0779).slice(1));  //79 
//总结
''+number 相当于 number.toString(10)
字符  unicode[十进制]  unicode[八进制]  unicode[十六进制]  Rex
'哈'  21704        52310       54c8            /u54c8/
'h'   104         150           68             /u0068/

字符  ASCII[十进制]    ASCII[八进制]    ASCII[十六进制]
'h'   104            160     68         /x68/

用肉眼观察可见, unicode码包含ASCII吗, 
ASCII的范围比较小   x00 ~ xff    
中文的unicode范围是  u4e00 ~ u9fa5
所以正则[^x00-xff]可表示占用两个字节的字符[就是我们常说的中文占用两个字节,英文占用1个字节的情况下]
BUT!
在UTF-8x下Unicode 中文会占3个字节,正确的对应关系是:
0x0000 ~ 0x007f 占1个字节;
0x0080 ~ 0x07ff 占2个字节;
0x0800 ~ 0xffff 占3个字节;
//转码函数
function transcoding(str){
        var rexAscii, rexUnicode, tempCode;
        rexAscii = /[x00-xff]/;
        tempCode = ('0000'+str.charCodeAt(0).toString(16)).slice(-4);
        return {
            ascii: rexAscii.test(str) ? '\x'+tempCode.slice(-2) : null,
            unicode: '\u'+tempCode
        }
    }
/** 关于eval */

//如果服务器响应的来的JSON是带有一个立即执行的函数,eval会解析他,会参数的后果就是能做everything
var text = '{"name":"sao", "age":"18", "add":(function(){alert(1)})()}';
var json1 = eval('('+text+')');        //解析
var json2 = JSON.parse(text);        //报错
console.log(json1);
console.log(json2);

//eval的上下文
var age = 1;
function foo(){
    var age = 2;
    eval('age = 3');
    return age;
}
somesayss.log(foo(), 1)        //3
somesayss.log(age, 1)        //1


var age = 1;
function foo(){
    var age = 2;
    window.eval('age = 3');
    return age;
}
somesayss.log(foo(), 1)        //FF,CHROM,IE9 2     IE6-8 3    
somesayss.log(age, 1)        //FF,CHROM,IE9 3     IE6-8 1

//globalEval
function globalEval(str){
    var WIN = window;
    return WIN.execScript ? WIN.execScript(str) : WIN.eval(str);
}
//字符串解析到json
//[函数]和[undefined] 是不能被解析的忽略, 数组内的undifined和function会解析成null
JSON.parse(string);
//json解析到字符串
//[函数]和[undefined]和[']号 是不能被解析的,直接报错
JSON.stringify(json);
//new Function 的作用域问题;永远都是在window下面
function foo(){
var a = 1; ;(new Function('a = 2;'))(); return a; } alert(foo());   //1 function foo(){ var a = 1; ;(function(){a = 2})(); return a; } alert(foo());    //2
//严格模式无法使用 arguments.caller
    function bbb(){
        console.log(arguments.callee.caller.toString())
    }
    ;(function(){
        bbb();
    })();
原文地址:https://www.cnblogs.com/somesayss/p/3145162.html