zoukankan      html  css  js  c++  java
  • javascript typeof用法小测

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type="text/javascript">
                
                
                
    function show(){
                    
    //typeof后跟参数,返回的是表示该参数类型的字符串
                    
                    
    var i = 5.5;     //number
                    
                    
    var j = "abc";   //string
                    var b = true;    //boolean
                    
                    
    var io = new Number("5.5");  //object
                    var jo = new String("abc");  //object
                    var bo = new Boolean(0);     //object
                    
                    
    var bo1 = Boolean(0);
                    
                  alert(
    typeof bo1);//boolean
                    
                    
    //alert( typeof  alert); //函数的类型都是function
                    
                    
    //alert(typeof k);//没有定义的值(或者理解为不存在)的类型都是undefined
                
                    
    /*
                    一些特殊的值
                    alert( typeof(NaN) );    //number                
                    alert( typeof(Infinity) );//number
                    
                    alert( typeof  null); //object
                    
    */
                    
                }
                
                
         
    //Boolean 对象
       //创建 Boolean 对象的语法:
         /*       new Boolean(value);    //构造函数
                 Boolean(value);        //转换函数    
                 
         参数:
              value 由布尔对象存放的值或者要转换成布尔值的值。

       返回值:
                    当作为一个构造函数(带有运算符 new)调用时,Boolean() 将把它的参数转换成一个布尔值,并且返回一个包含该值的 Boolean 对象。

                    如果作为一个函数(不带有运算符 new)调用时,Boolean() 只将把它的参数转换成一个原始的布尔值,并且返回这个值。

         注释:如果省略 value 参数,或者设置为 0、-0、null、""、false、undefined 或 NaN,则该对象设置为 false。否则设置为 true(即使 value 参数是字符串 "false")。
        
       
    */

        
    </script>
    </head>
    <body>
    <input type="button" value=" click me " onclick="show()"/>
    </body>
    </html>
  • 相关阅读:
    Leetcode-921 Minimum Add to Make Parentheses Valid(使括号有效的最少添加)
    Leetcode-922 Sort Array By Parity II(按奇偶排序数组 II)
    Leetcode-827 Making A Large Island(最大人工岛)
    Leetcode-766 Toeplitz Matrix(托普利茨矩阵)
    Leetcode-919 Complete Binary Tree Inserter(完全二叉树插入器)
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/Fskjb/p/2498622.html
Copyright © 2011-2022 走看看