<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、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ### 值 #### 一、數組 數組本身就是對象 ``` var a = [0]; a.length; //1 a["name"] = "qc"; a.length; //1 a["name"]; //qc a.name; //qc var b = [0]; b.length; //1 //如果屬性能被強制轉換為十進制數字時,將會被當做數組索引使用 b["10"] = 42; b.length; //11 ``` 偽數組使用數組的api ``` function foo() { var arr = Array.prototype.slice.call(arguments); arr.push('bam'); console.log(arr); } foo('bar', 'baz'); // ['bar', 'baz', 'bam'] ``` #### 二、字符串 字符串如何借用數組的api ``` var a = "foo"; var c = Array.prototype.join.call(a, "-"); //f-o-o var d = Array.prototype.map.call(a, function(v) { return v.toUpperCase() + "." }).join(""); //F.O.O. ``` #### 三、數字 js使用的是雙精度格式的浮點數(即64位二進制) ``` var a = 42\42.5\.5\42.\42.0 var b = 5E10 //50000000000 b.toExponential(); //"5e+10" //特別大和特別小的數字默認使用指數格式 var c = b * b; //2.5e+21 ``` 小數點非0數字后面的所有0都會被忽略掉 toFixed和toPrecision ``` var a = 42.59 a.toFixed(0); //"43" a.toFixed(1); //"42.6" a.toFixed(2); //"42.59" a.toFixed(3); //"42.590" a.toFixed(4); //"42.5900" a.toPrecision(1); //"4e+1" a.toPrecision(2); //"43" a.toPrecision(3); //"42.6" a.toPrecision(4); //"42.59" a.toPrecision(5); //"42.590" a.toPrecision(6); //"42.5900" ``` ``` var a = 42; a.toFixed(3); //"42.000" //.被視為42的一部分 42.toFixed(3); //SyntaxError (42).toFixed(3); //"42.000" //相當于(42.).toFixed(3),第一個.被視為42的一部分,第二個.調用toFixed 42..toFixed(3); //"42.000" ``` 小數的運算 ``` 0.1 + 0.2 != 0.3 //相加的結果可能是0.30000000000004 //常見的解決方案是指定一個誤差范圍 if(!Number.EPSILON) Number.EPSILON = Math.pow(2, -52); function isEqual(n1, n2) { return Math.abs(n1, n2) < Number.EPSILON; } isEqual(0.1 + 0.2, 0.3) ; //true ``` 整數的安全值范圍是-2^53 + 1到2^53 - 1,超過這個范圍就會產生精度丟失,變為無窮數Infinity 檢測一個變量是否是整數 ``` //es6 Number.isInteger(n); //es5 //typeof NaN 一樣是number //NaN % 1 -> NaN typeof n == "number" && n % 1 == 0 ``` 檢測一個數字是否安全 ``` //es6 Number.isSafeInteger(n); //es5 typeof n == "number" && n % 1 ==0 && Math.abs(n) <= Number.MAX_SAFE_INTEGER ``` #### 四、特殊數值 null和undefined的區別 null指空值,undefined指沒有值;null指曾賦過值,現在沒有值,undefined值從未賦過值;null是特殊關鍵字,不是標識符,不能當做變量來使用,而undefined是標識符,可以當做變量使用。 void:讓表達式不返回值,但變量本身沒有被更改 ``` var a = 2; console.log(void a, a); //undefined 2 ``` 任何與NaN所做的比較均為false ``` var a = 2 / "foo"; a; //NaN a == NaN; //false a === NaN; //false NaN !=(!===) NaN; //true ``` 比較兩個值是否相等(適用于所有情況) ``` //es6 Object.is(a, b) //es5 Object.is = function(a, b) { if(a === 0 && b === 0) { return 1 / a === 1 / b //-0的情況,因為1/-為-Infinity, 0===-0為true } if(a !== a){ return b !== b //NaN的情況 } else { return a === b } } ``` #### 五、值和引用 單值:number、string、null、undefined、boolean 復合值:object(包括array)、function ``` var a = [1, 2, 3]; var b = a; b.push(4); a; //[1, 2, 3, 4]; //改變了b的引用 b = [7, 8, 9]; b.push(10); b; //[7, 8, 9, 10] a; //[1, 2, 3, 4] //只是清空數組,并沒有更改引用 b = a; b.length = 0; b; //[] a; //[] ```
                  <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>

                              哎呀哎呀视频在线观看