<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] ## **typeOf返回類型** > number、string、boolean、undefined、null、object、function ``` var a = 20; var str = "hello"; var c = true; console.log(typeof a); //number console.log(typeof str); //string console.log(typeof c);//boolean ``` ## **比較typeof與instanceof?** ### **相同點** > JavaScript 中 typeof 和 instanceof 常用來判斷一個變量是否為空,或者是什么類型的。 **typeof的定義和用法**:返回值是一個字符串,用來說明變量的數據類型。 ### **細節** 1. typeof 一般只能返回如下幾個結果:number,boolean,string,function,object,undefined。 2. typeof 來獲取一個變量是否存在,如 if(typeof a!="undefined"){alert("ok")},而不要去使用 if(a) 因為如果 a 不存在(未聲明)則會出錯。 3. 對于 Array,Null 等特殊對象使用 typeof 一律返回 object,這正是 typeof 的局限性。 **Instanceof定義和用法**:instanceof 用于判斷一個變量是否屬于某個對象的實例。 實例演示: ``` a instanceof b?alert("true"):alert("false"); //a是b的實例?真:假 ``` ``` var a = new Array(); alert(a instanceof Array); // true alert(a instanceof Object)? // true ``` 如上,會返回 true,同時 alert(a instanceof Object) 也會返回 true;這是因為 Array 是 object?的子類。 ``` function test(){}; var a = new test(); alert(a instanceof test) // true ``` ### **細節** * 如下,得到的結果為‘N’,這里的 instanceof 測試的 object 是指 js 語法中的 object,不是指 dom 模型對象。 ``` if (window instanceof Object){ alert('Y')} else { alert('N');} // 'N' ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看