<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 7.在控制臺上打印信息(`console.*`) > 原文: [http://exploringjs.com/impatient-js/ch_console.html](http://exploringjs.com/impatient-js/ch_console.html) > > 貢獻者:[Hunter-liu](https://github.com/lq920320) 打印是不屬于 JavaScript 語言標準的功能。但是,我們在這里進行的所有操作,瀏覽器和 Node.js 都是支持的。 打印意味著“在控制臺上顯示內容”,其中“控制臺”是瀏覽器控制臺或運行 Node.js 的終端。 完整的`console.*` API 在 [MDN 的網頁](https://developer.mozilla.org/en-US/docs/Web/API/console) 以及 [Node.js 官網](https://nodejs.org/api/console.html)都有相關文檔。接下來我們將快速瀏覽以下兩個操作: - `console.log()` - `console.error()` ### 7.1. 打印值:`console.log()`(標準輸出) 此操作有兩種形式: ```js console.log(...values: any[]): void console.log(pattern: string, ...values: any[]): void ``` #### 7.1.1. 打印多個值 第一中形式在控制臺上打印(文本)值: ```js console.log('abc', 123, true); // Output: // abc 123 true ``` `console.log()` 始終在末尾打印換行符。因此,如果你直接調用而不加任何參數,它只會打印一個換行符。 #### 7.1.2. 打印替換的字符串 第二種形式可以進行替換字符串: ```js console.log('Test: %s %j', 123, 'abc'); // Output: // Test: 123 "abc" ``` 你可以用于替換的一些指令: - `%s`將相應的值轉換為字符串輸出。 ```js console.log('%s %s', 'abc', 123); // Output: // abc 123 ``` - `%o`將被替換的對象轉為字符串形式輸出。 ```js console.log('%o', {foo: 123, bar: 'abc'}); // Output: // { foo: 123, bar: 'abc' } ``` - `%j`將被替換的值轉換為 JSON 字符串輸出。 ```js console.log('%j', {foo: 123, bar: 'abc'}); // Output: // {"foo":123,"bar":"abc"} ``` - `%%`插入一個`%`。 ```js console.log('%s%%', 99); // Output: // 99% ``` ### 7.2. 打印錯誤信息:`console.error()`(標準錯誤) `console.error()`與`console.log()`的作用相同,但它的日志內容被視為錯誤信息。對于 Node.js,這意味著在 Unix 上輸出的是 stderr(標準錯誤) 而不是 stdout(標準輸出)。 ### 7.3. 通過`JSON.stringify()`打印嵌套對象 [`JSON.stringify()`](/docs/50.md#4131-jsonstringifyvalue-replacer-space) 偶爾用于打印嵌套對象: ```js console.log(JSON.stringify({first: 'Jane', last: 'Doe'}, null, 2)); ``` 輸出: ```js { "first": "Jane", "last": "Doe" } ```
                  <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>

                              哎呀哎呀视频在线观看