{"id":1392,"date":"2022-07-10T22:59:59","date_gmt":"2022-07-10T14:59:59","guid":{"rendered":"https:\/\/zhuxinyong.com\/?p=1392"},"modified":"2022-07-13T08:25:31","modified_gmt":"2022-07-13T00:25:31","slug":"15-javascript-zhong-de-diao-shiconsole-de-fang-fa","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=1392","title":{"rendered":"15 &#8211; JavaScript \u4e2d\u7684\u8c03\u8bd5\uff1aconsole \u7684\u65b9\u6cd5"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/07\/16574652379187.jpg\" alt=\"\" \/><\/p>\n<p>\u539f\u6587\u5730\u5740\uff1a<a href=\"https:\/\/dev.to\/bhagatparwinder\/debugging-in-javascript-console-methods-2de2\" target=\"_blank\" rel=\"noopener\">https:\/\/dev.to\/bhagatparwinder\/debugging-in-javascript-console-methods-2de2<\/a><\/p>\n<h2><a id=\"javascript%E4%B8%AD-console%E5%AF%B9%E8%B1%A1%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>JavaScript \u4e2d console \u5bf9\u8c61\u662f\u4ec0\u4e48\uff1f<\/h2>\n<p><code>console<\/code> \u5bf9\u8c61\u63d0\u4f9b\u4e86\u8c03\u8bd5\u6253\u5370\u7684\u80fd\u529b\uff0c\u5b83\u662f\u4e00\u4e2a\u5168\u5c40\u5bf9\u8c61\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u83b7\u53d6\u3002\u5728\u4efb\u4f55\u4ee3\u7801\u4e2d\u95ee\u9898\u5b9a\u4f4d\u90fd\u662f\u5f88\u5e38\u89c1\u7684\uff0cconsole \u65b9\u6cd5\u4f7f\u5f97\u6253\u5370\u8bed\u53e5\u3001\u53d8\u91cf\u3001\u65b9\u6cd5\u548c\u9519\u8bef\u53d8\u5f97\u7b80\u5355\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">console.log(&quot;Running the program...&quot;);\n\/\/ Running the program...\n<\/code><\/pre>\n<p><code>log<\/code> \u662f\u4e00\u4e2a\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u5b83\u6253\u5370\u663e\u793a\u7684\u662f\u4f60\u4f20\u9012\u7ed9\u5b83\u7684\u4fe1\u606f\uff0c<code>log<\/code> \u88ab\u7528\u4e8e\u5e38\u89c4\u76ee\u7684\u7684\u6253\u5370\u3002<\/p>\n<h2><a id=\"assert\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Assert<\/h2>\n<p>\u5f53 <code>console.assert()<\/code> \u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f false \u7684\u65f6\u5019\uff0c\u4f1a\u6253\u5370\u4fe1\u606f\u548c\u5806\u6808\u5230\u63a7\u5236\u53f0\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">const error = &quot;Number is not divisible by 2&quot;;\nconsole.assert(5 % 2 === 0, { errorMsg: error });\n\/\/ Assertion failed: { errorMsg: &quot;Number is not divisible by 2&quot; }\nconsole.assert(4 % 2 === 0, { errorMsg: error });\n\/\/ No output for this statement as assertion is true\n<\/code><\/pre>\n<h2><a id=\"clear\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Clear<\/h2>\n<p>\u82e5\u73af\u5883\u5141\u8bb8 clear \u80fd\u6e05\u7a7a\u63a7\u5236\u53f0\u3002<\/p>\n<h2><a id=\"dir\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Dir<\/h2>\n<p><code>console.dir<\/code> \u53ef\u4ee5\u5c55\u793a\u4e00\u4e2a\u53ef\u4ea4\u4e92\u7684\u7279\u5b9a JavaScript \u5bf9\u8c61\u4e0a\u7684\u5c5e\u6027\u5217\u8868\u3002\u4f8b\u5982\uff1a\u82e5\u6211\u8bbf\u95ee\u4e86 google \u5e76\u4e14\u5728\u63a7\u5236\u53f0\u6267\u884c\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">console.dir(document.location);\n<\/code><\/pre>\n<p><code>dir<\/code> \u5c06\u4f1a\u6253\u5370\u51fa\u6d4f\u89c8\u5668\u6587\u6863\u63d0\u4f9b\u7684 location \u5bf9\u8c61\u4e0a\u7684\u6240\u6709\u5c5e\u6027\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/07\/16576016413544.jpg\" alt=\"\" \/><\/p>\n<h2><a id=\"error\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Error<\/h2>\n<p><code>console.error<\/code> \u4e0e log \u65b9\u6cd5\u7c7b\u4f3c\uff0c\u5b83\u88ab\u7528\u4e8e\u8f93\u51fa\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">console.error(&quot;Process exited with code 1&quot;);\n\/\/ Process exited with code 1\n<\/code><\/pre>\n<h2><a id=\"log\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Log<\/h2>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">console.log(&quot;Running the program...&quot;);\n\/\/ Running the program...\n<\/code><\/pre>\n<p><code>log<\/code> \u662f\u7528\u7684\u6700\u591a\u7684\u65b9\u6cd5\u3002\u5b83\u4f1a\u628a\u4f60\u4f20\u9012\u7ed9\u5b83\u7684\u4fe1\u606f\u663e\u793a\u51fa\u6765\u3002<code>log<\/code> \u7528\u4e8e\u666e\u901a\u7684\u6253\u5370\u3002<\/p>\n<p><code>log<\/code> \u548c <code>dir<\/code> \u5728\u8bb8\u591a\u65b9\u6cd5\u90fd\u7c7b\u4f3c\u4f46\u4e0d\u540c\u7684\u5728\u4e8e\u5982\u4f55\u8f93\u51fa\u3002\u5047\u5982\uff0c\u90fd\u4f20\u9012\u4e00\u4e2a\u5bf9\u8c61\uff0c<code>dir<\/code> \u4f1a\u8f93\u51fa\u4e00\u4e2a\u53ef\u4ea4\u4e92\u7684\u5bf9\u8c61\u5c5e\u6027\u5217\u8868\u4e14\u5bb9\u6613\u5b9a\u4f4d\uff0c\u7136\u800c <code>log<\/code> \u5219\u4f1a\u6253\u5370\u51fa\u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\u5f62\u5f0f\u3002<\/p>\n<h2><a id=\"table\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Table<\/h2>\n<p><code>console.table<\/code> \u662f\u4e00\u4e2a\u6700\u88ab\u4f4e\u4f30\u7684\u6253\u5370\u65b9\u6cd5\u3002\u5b83\u4f1a\u628a\u6570\u636e\u8f93\u51fa\u6210\u8868\u683c\u5f62\u5f0f\uff0c\u4f7f\u9605\u8bfb\u66f4\u5bb9\u6613\u3002\u9996\u5148\u662f\u8fd9\u4e2a\u6570\u636e\u53ef\u4ee5\u5728\u8868\u683c\u4e2d\u663e\u793a\uff08\u6570\u7ec4\u548c\u5bf9\u8c61\uff09\u3002<\/p>\n<p>\u4ee5\u6570\u7ec4\u4e3a\u4f8b\uff0c\u6253\u5370\u51fa\u8868\u683c\u7684\u4e00\u5217\u662f\u7d22\u5f15\u4e00\u5217\u662f\u503c\uff0c\u800c\u5bf9\u4e8e\u5bf9\u8c61\uff0c\u4e00\u5217\u662f key \u53e6\u4e00\u5217\u662f\u503c\u3002<\/p>\n<p><code>table<\/code> \u8fd8\u6709\u4e00\u4e2a\u53ef\u9009\u53c2\u6570\u4f5c\u4e3a\u5217\u7684\u8f93\u51fa\u6807\u7b7e\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/07\/16576709614601.jpg\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/07\/16576710464066.jpg\" alt=\"\" \/><\/p>\n<h2><a id=\"time\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>time<\/h2>\n<p><code>console.time()<\/code> \u521b\u5efa\u4e86\u4e00\u4e2a\u5e26\u6709\u53ef\u9009\u540d\u5b57\/\u6807\u7b7e\u7684\u5b9a\u65f6\u5668\uff0c\u9875\u9762\u4e0a\u53ef\u4ee5\u540c\u65f6\u6709 10000 \u4e2a\u5b9a\u65f6\u5668\u8fd0\u884c\uff0c\u7528\u6765\u6d4b\u91cf\u4e00\u4e2a\u64cd\u4f5c\u8017\u8d39\u4e86\u591a\u957f\u65f6\u95f4\u3002<\/p>\n<h2><a id=\"timeend\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>timeEnd<\/h2>\n<p>\u4f7f\u4f60\u53ef\u4ee5\u7ec8\u6b62\u53f3 <code>console.time<\/code> \u521b\u5efa\u7684\u5b9a\u65f6\u5668\u3002<\/p>\n<h2><a id=\"trace\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>trace<\/h2>\n<p>\u7528\u6765\u8f93\u51fa\u8ffd\u4e2d\u6808\u5230\u63a7\u5236\u53f0<\/p>\n<h2><a id=\"warn\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>warn<\/h2>\n<p><code>console.warn<\/code> \u5728\u63a7\u5236\u53f0\u8f93\u51fa\u8b66\u544a\u4fe1\u606f\uff0c\u82e5\u4f60\u5728 Firefox \u6216 Chrome \u4e2d\u4f7f\u7528\uff0c\u5728\u6253\u5370\u7684\u4fe1\u606f\u524d\u9762\u4f60\u4f1a\u770b\u5230\u4e00\u4e2a\u9ec4\u8272\u7684\u611f\u53f9\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740\uff1ahttps:\/\/dev.to\/bhagatparwinder\/debugging-in-j&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,20,3],"tags":[186,75],"class_list":["post-1392","post","type-post","status-publish","format-standard","hentry","category-all","category-frontend","category-tech","tag-console","tag-75"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1392"}],"version-history":[{"count":1,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1392\/revisions"}],"predecessor-version":[{"id":1393,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1392\/revisions\/1393"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}