{"id":3294,"date":"2024-11-10T12:06:31","date_gmt":"2024-11-10T04:06:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3294\/"},"modified":"2024-11-10T12:06:31","modified_gmt":"2024-11-10T04:06:31","slug":"js%e5%a6%82%e4%bd%95%e4%bc%a0%e5%85%a5%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3294\/","title":{"rendered":"js\u5982\u4f55\u4f20\u5165\u503c"},"content":{"rendered":"<blockquote><p>\n  javascript \u4f20\u9012\u503c\u7684\u65b9\u6cd5\u6709\uff1a1. \u51fd\u6570\u53c2\u6570\uff1b2. \u5168\u5c40\u53d8\u91cf\uff1b3. \u5bf9\u8c61\uff1b4. \u6570\u7ec4\uff1b5. \u56de\u8c03\u51fd\u6570\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110809152096428.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u4f20\u5165\u503c\u63d2\u56fe\" alt=\"js\u5982\u4f55\u4f20\u5165\u503c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 JavaScript \u4f20\u9012\u503c<\/strong><\/p>\n<p><strong>\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>JavaScript \u4e2d\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u4f20\u9012\u503c\uff1a<\/p>\n<p><strong>1. \u51fd\u6570\u53c2\u6570\uff1a<\/strong><\/p>\n<ul>\n<li>\u5c06\u503c\u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570\u4f20\u9012\u3002<\/li>\n<li><strong>\u793a\u4f8b\uff1a<\/strong><\/li>\n<\/ul>\n<pre>function myFunction(name) {\n  console.log(\"My name is \" + name);\n}\n\nmyFunction(\"John\"); \/\/ \u8f93\u51fa\uff1a\"My name is John\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u5168\u5c40\u53d8\u91cf\uff1a<\/strong><\/p>\n<ul>\n<li>\u58f0\u660e\u5728\u5168\u5c40\u4e2d\u7684\u53d8\u91cf\u53ef\u5728\u4efb\u4f55\u5730\u65b9\u8bbf\u95ee\u3002<\/li>\n<li><strong>\u793a\u4f8b\uff1a<\/strong><\/li>\n<\/ul>\n<pre>var globalVariable = \"Hello world\";\n\nfunction accessGlobalVariable() {\n  console.log(globalVariable); \/\/ \u8f93\u51fa\uff1a\"Hello world\"\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u5bf9\u8c61\uff1a<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u503c\u7684\u5bf9\u8c61\uff0c\u7136\u540e\u4f20\u9012\u8be5\u5bf9\u8c61\u3002<\/li>\n<li><strong>\u793a\u4f8b\uff1a<\/strong><\/li>\n<\/ul>\n<pre>var person = {\n  name: \"John\",\n  age: 30\n};\n\nfunction displayPersonInfo(person) {\n  console.log(\"Name: \" + person.name);\n  console.log(\"Age: \" + person.age);\n}\n\ndisplayPersonInfo(person);\n\/\/ \u8f93\u51fa\uff1a\"Name: John\"\n\/\/ \u8f93\u51fa\uff1a\"Age: 30\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u6570\u7ec4\uff1a<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u503c\u7684\u6570\u7ec4\uff0c\u7136\u540e\u4f20\u9012\u8be5\u6570\u7ec4\u3002<\/li>\n<li><strong>\u793a\u4f8b\uff1a<\/strong><\/li>\n<\/ul>\n<pre>var numbers = [1, 2, 3];\n\nfunction sumNumbers(numbers) {\n  var sum = 0;\n  for (var i = 0; i &lt; numbers.length; i++) {\n    sum += numbers[i];\n  }\n  return sum;\n}\n\nconsole.log(sumNumbers(numbers)); \/\/ \u8f93\u51fa\uff1a6<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u56de\u8c03\u51fd\u6570\uff1a<\/strong><\/p>\n<ul>\n<li>\u5c06\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53e6\u4e00\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u4f20\u9012\u3002<\/li>\n<li><strong>\u793a\u4f8b\uff1a<\/strong><\/li>\n<\/ul>\n<pre>function myFunction(successCallback, errorCallback) {\n  \/\/ \u6267\u884c\u4e00\u4e9b\u64cd\u4f5c...\n\n  if (success) {\n    successCallback();\n  } else {\n    errorCallback();\n  }\n}\n\nmyFunction(\n  function() {\n    console.log(\"Success!\");\n  },\n  function() {\n    console.log(\"Error!\");\n  }\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u4f20\u5165\u503c\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>javascript \u4f20\u9012\u503c\u7684\u65b9\u6cd5\u6709\uff1a1. \u51fd\u6570\u53c2\u6570\uff1b2. \u5168\u5c40\u53d8\u91cf\uff1b3. \u5bf9\u8c61\uff1b4. \u6570\u7ec4\uff1b5. \u56de\u8c03\u51fd\u6570\u3002 \u5982\u4f55\u4f7f\u7528 JavaScript \u4f20\u9012\u503c \u65b9\u6cd5\uff1a JavaScript \u4e2d\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u4f20\u9012\u503c\uff1a 1. \u51fd\u6570\u53c2\u6570\uff1a \u5c06\u503c\u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570\u4f20\u9012\u3002 \u793a\u4f8b\uff1a function myFunction(name) { console.log(&#8220;My name is &#8221; + name); } myFunction(&#8220;John&#8221;); \/\/ \u8f93\u51fa\uff1a&#8221;My name is John&#8221; \u767b\u5f55\u540e\u590d\u5236 2. \u5168\u5c40\u53d8\u91cf\uff1a \u58f0\u660e\u5728\u5168\u5c40\u4e2d\u7684\u53d8\u91cf\u53ef\u5728\u4efb\u4f55\u5730\u65b9\u8bbf\u95ee\u3002 \u793a\u4f8b\uff1a var globalVariable = &#8220;Hello world&#8221;; function accessGlobalVariable() { console.log(globalVariable); \/\/ \u8f93\u51fa\uff1a&#8221;Hello world&#8221; } \u767b\u5f55\u540e\u590d\u5236 3. \u5bf9\u8c61\uff1a \u521b\u5efa\u4e00\u4e2a\u5305\u542b\u503c\u7684\u5bf9\u8c61\uff0c\u7136\u540e\u4f20\u9012\u8be5\u5bf9\u8c61\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3294","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3294"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3294\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}