饥人谷技术博客

JS语法

2016-08-12  本文已影响43人  Nicklzy

CSS和JS在网页中的放置顺序是怎样的?

解释白屏和FOUC

async和defer的作用是什么?有什么区别

简述网页的渲染机制

JavaScript 定义了几种数据类型? 哪些是简单类型?哪些是复杂类型?

NaN、undefined、null分别代表什么?

typeof和instanceof的作用和区别?

代码

  1. 完成如下代码判断一个变量是否是数字、字符串、布尔、函数
    function isNumber(el){
    }
    function isString(el){
    }
    function isBoolean(el){
    }
    function isFunction(el){
    }
    var a = 2,
    b = 'jirengu',
    c = false;
    alert( isNumber(a) ); //true
    alert( isString(a) ); //false
    alert( isString(b) ); //true
    alert( isBoolean(c) ); //true
    alert( isFunction(a)); //false
    alert( isFunction( isNumber ) ); //true
    代码如下:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    </head>
    <body>
    <script>
    function isNumber(el){
    return (typeof el == 'number');
    }
    function isString(el){
    return (typeof el == 'string');
    }
    function isBoolean(el){
    return (typeof el == 'boolean');
    }
    function isFunction(el){
    return (typeof el == 'function');
    }
    var a = 2,
    b = 'jirengu',
    c = false;
    alert( isNumber(a) ); //true
    alert( isString(a) ); //false
    alert( isString(b) ); //true
    alert( isBoolean(c) ); //true
    alert( isFunction(a)); //false
    alert( isFunction( isNumber ) ); //true
    </script>
    </body>
    </html>
  2. 以下代码的输出结果是?
    console.log(1+1); //2 在两个操作数都是数字的时候,会做加法运算
    console.log("2"+"4"); //"24" 两个参数都是字符串或在有一个参数是字符串的情况下会把另外一个参数转换为字符串做字符串拼接
    console.log(2+"4"); // "24" 同上
    console.log(+new Date());//从'1970/01/01 00:00:00'为起点,开始叠加的毫秒数。
    console.log(+"4"); //4 在只有一个字符串参数的时候会尝试将其转换为数字

本文版权归本人和饥人谷所有,转载请注明来源。

上一篇下一篇

猜你喜欢

热点阅读