{"id":170747,"date":"2024-05-08T17:14:18","date_gmt":"2024-05-08T09:14:18","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/170747.html"},"modified":"2024-05-08T17:14:23","modified_gmt":"2024-05-08T09:14:23","slug":"javascript-%e7%bc%96%e7%a8%8b%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%8a%a0%e5%87%8f%e4%b9%98%e9%99%a4%e8%bf%90%e7%ae%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/170747.html","title":{"rendered":"javascript \u7f16\u7a0b\u5982\u4f55\u5b9e\u73b0\u52a0\u51cf\u4e58\u9664\u8fd0\u7b97"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27041555\/e10860d1-2359-48c7-b5fd-758782f68acf.webp\" alt=\"javascript \u7f16\u7a0b\u5982\u4f55\u5b9e\u73b0\u52a0\u51cf\u4e58\u9664\u8fd0\u7b97\" \/><\/p>\n<p><p>\u5728JavaScript\u7f16\u7a0b\u4e2d\uff0c\u5b9e\u73b0\u52a0\u51cf\u4e58\u9664\u8fd0\u7b97\u662f\u57fa\u7840\u64cd\u4f5c\u7684\u6838\u5fc3\u90e8\u5206\u3002\u8fd9\u4e9b\u57fa\u672c\u7684\u7b97\u672f\u8fd0\u7b97\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528JavaScript\u5185\u7f6e\u7684\u8fd0\u7b97\u7b26\u6765\u5b9e\u73b0\u3001\u5206\u522b\u662f\u52a0<code>+<\/code>\u3001\u51cf<code>-<\/code>\u3001\u4e58<code>*<\/code>\u3001\u9664<code>\/<\/code>\u3002\u8fd9\u4e9b\u8fd0\u7b97\u7b26\u53ef\u4ee5\u76f4\u63a5\u5e94\u7528\u5728\u6570\u5b57\u3001\u53d8\u91cf\u3001\u751a\u81f3\u8868\u8fbe\u5f0f\u4e0a\uff0c\u4ece\u800c\u5b8c\u6210\u57fa\u672c\u7684\u6570\u5b66\u8ba1\u7b97\u3002\u7279\u522b\u662f\u5728\u8fdb\u884c\u590d\u6742\u7684\u6570\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5904\u7406\u65f6\uff0c\u638c\u63e1\u8fd9\u4e9b\u57fa\u7840\u8fd0\u7b97\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><p>\u5c55\u5f00\u8be6\u7ec6\u63cf\u8ff0\u8fd0\u7b97\u7b26\u7684\u4f7f\u7528\uff1a\u5728JavaScript\u4e2d\uff0c\u52a0\u6cd5\u8fd0\u7b97\u7b26<code>+<\/code>\u4e0d\u4ec5\u7528\u4e8e\u6570\u5b57\u7684\u76f8\u52a0\uff0c\u8fd8\u80fd\u7528\u4e8e\u5b57\u7b26\u4e32\u7684\u8fde\u63a5\u3002\u8fd9\u4f7f\u5f97<code>+<\/code>\u8fd0\u7b97\u7b26\u53d8\u5f97\u7279\u522b\u7075\u6d3b\u3002\u4f8b\u5982\uff0c\u5f53\u4e24\u4e2a\u6570\u5b57\u4f7f\u7528<code>+<\/code>\u8fdb\u884c\u8fde\u63a5\u65f6\uff0c\u5b83\u4eec\u4f1a\u88ab\u76f8\u52a0\uff08\u59825 + 10 = 15\uff09\uff0c\u4f46\u5982\u679c\u81f3\u5c11\u4e00\u4e2a\u64cd\u4f5c\u6570\u662f\u5b57\u7b26\u4e32\uff0c<code>+<\/code>\u4f1a\u5c06\u5176\u4f59\u64cd\u4f5c\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u5e76\u8fdb\u884c\u8fde\u63a5\uff08\u5982&quot;5&quot; + 10 = &quot;510&quot;\uff09\u3002\u8fd9\u79cd\u884c\u4e3a\u5bf9\u4e8e\u5904\u7406\u6570\u5b57\u548c\u6587\u672c\u6570\u636e\u7279\u522b\u6709\u7528\uff0c\u4f46\u4e5f\u8981\u5c0f\u5fc3\u64cd\u4f5c\u6570\u7684\u7c7b\u578b\uff0c\u4ee5\u9632\u6b62\u51fa\u73b0\u9884\u671f\u5916\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u52a0\u6cd5\u8fd0\u7b97\uff08+\uff09<\/h3>\n<\/p>\n<p><p>\u5728JavaScript\u4e2d\uff0c\u8fdb\u884c\u52a0\u6cd5\u8fd0\u7b97\u975e\u5e38\u76f4\u63a5\uff0c\u53ea\u9700\u4f7f\u7528<code>+<\/code>\u8fd0\u7b97\u7b26\u3002\u4e0d\u4ec5\u53ef\u4ee5\u5904\u7406\u6570\u5b57\uff0c\u8fd8\u53ef\u4ee5\u8fde\u63a5\u5b57\u7b26\u4e32\uff0c\u8fd9\u70b9\u662f\u5176\u72ec\u7279\u4e4b\u5904\u3002\u6bd4\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">let num1 = 5;<\/p>\n<p>let num2 = 10;<\/p>\n<p>let sum = num1 + num2;  \/\/ \u7ed3\u679c\u662f15<\/p>\n<p>let str1 = &quot;Hello, &quot;;<\/p>\n<p>let str2 = &quot;world!&quot;;<\/p>\n<p>let greeting = str1 + str2;  \/\/ \u7ed3\u679c\u662f&quot;Hello, world!&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u51cf\u6cd5\u8fd0\u7b97\uff08-\uff09<\/h3>\n<\/p>\n<p><p>\u51cf\u6cd5\u8fd0\u7b97\u4f7f\u7528<code>-<\/code>\u8fd0\u7b97\u7b26\uff0c\u9002\u7528\u4e8e\u4ece\u4e00\u4e2a\u6570\u503c\u4e2d\u51cf\u53bb\u53e6\u4e00\u4e2a\u6570\u503c\u3002\u5728\u80a1\u7968\u5e02\u573a\u6570\u636e\u5904\u7406\u548c\u65f6\u95f4\u8ba1\u7b97\u7b49\u5e94\u7528\u4e2d\uff0c\u51cf\u6cd5\u8fd0\u7b97\u975e\u5e38\u5b9e\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">let startValue = 100;<\/p>\n<p>let expenditure = 40;<\/p>\n<p>let balance = startValue - expenditure;  \/\/ \u7ed3\u679c\u662f60<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u51cf\u6cd5\u8fd0\u7b97\u4e5f\u53ef\u4ee5\u7528\u4e8e\u65e5\u671f\u65f6\u95f4\u5dee\u503c\u7684\u8ba1\u7b97\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u5904\u7406\u65f6\u95f4\u76f8\u5173\u7684\u903b\u8f91\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4e58\u6cd5\u8fd0\u7b97\uff08*\uff09<\/h3>\n<\/p>\n<p><p>\u4e58\u6cd5\u8fd0\u7b97\u901a\u8fc7<code>*<\/code>\u8fd0\u7b97\u7b26\u5b9e\u73b0\uff0c\u5b83\u7528\u4e8e\u8ba1\u7b97\u4e24\u4e2a\u6570\u7684\u4e58\u79ef\u3002\u5728\u5904\u7406\u7edf\u8ba1\u6570\u636e\u3001\u8ba1\u7b97\u9762\u79ef\u7b49\u573a\u666f\u4e0b\uff0c\u4e58\u6cd5\u8fd0\u7b97\u5c55\u73b0\u51fa\u91cd\u8981\u7684\u4f5c\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">let length = 10;<\/p>\n<p>let width = 5;<\/p>\n<p>let area = length * width;  \/\/ \u7ed3\u679c\u662f50<\/p>\n<p>let price = 199;<\/p>\n<p>let quantity = 3;<\/p>\n<p>let totalCost = price * quantity;  \/\/ \u7ed3\u679c\u662f597<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u9664\u6cd5\u8fd0\u7b97\uff08\/\uff09<\/h3>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u9664\u6cd5\u8fd0\u7b97\u901a\u8fc7<code>\/<\/code>\u8fd0\u7b97\u7b26\u5b8c\u6210\uff0c\u7528\u4e8e\u4e24\u4e2a\u6570\u503c\u7684\u9664\u6cd5\u8ba1\u7b97\u3002\u65e0\u8bba\u662f\u5728\u91d1\u878d\u8ba1\u7b97\u3001\u6570\u636e\u5206\u6790\u8fd8\u662f\u65e5\u5e38\u7f16\u7a0b\u95ee\u9898\u4e2d\uff0c\u638c\u63e1\u9664\u6cd5\u8fd0\u7b97\u90fd\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">let totalDistance = 100;<\/p>\n<p>let totalTime = 20;<\/p>\n<p>let speed = totalDistance \/ totalTime;  \/\/ \u7ed3\u679c\u662f5, \u5373\u901f\u5ea6\u662f\u6bcf\u5c0f\u65f65\u5355\u4f4d\u8ddd\u79bb<\/p>\n<p>let totalBill = 450;<\/p>\n<p>let numberOfPeople = 3;<\/p>\n<p>let perPersonCost = totalBill \/ numberOfPeople;  \/\/ \u7ed3\u679c\u662f150<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u9664\u4e86\u8fd9\u4e9b\u57fa\u7840\u7684\u8fd0\u7b97\uff0cJavaScript\u8fd8\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u9ad8\u7ea7\u7684\u6570\u5b66\u8ba1\u7b97\u65b9\u6cd5\uff0c\u5982\u6c42\u4f59\uff08<code>%<\/code>\uff09\u3001\u6307\u6570\uff08<code><\/code>\uff09\u7b49\uff0c\u901a\u8fc7<code>Math<\/code>\u5bf9\u8c61\u53ef\u4ee5\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u6570\u5b66\u8fd0\u7b97\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u5706\u5468\u7387\u8ba1\u7b97\u3001\u5e73\u65b9\u6839\u3001\u7edd\u5bf9\u503c\u7b49\u3002\u719f\u7ec3\u638c\u63e1\u8fd9\u4e9b\u8fd0\u7b97\u5bf9\u4e8e\u8fdb\u884c\u9ad8\u6548\u4e14\u51c6\u786e\u7684\u6570\u636e\u5904\u7406\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>Q: \u5728 JavaScript \u4e2d\u5982\u4f55\u5b9e\u73b0\u52a0\u6cd5\u8fd0\u7b97\uff1f<\/strong><\/p>\n<p>A: \u5728 JavaScript \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u52a0\u53f7\uff08+\uff09\u7b26\u53f7\u6765\u5b9e\u73b0\u52a0\u6cd5\u8fd0\u7b97\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06\u4e24\u4e2a\u6570\u5b57\u76f8\u52a0\u6765\u5f97\u5230\u5b83\u4eec\u7684\u603b\u548c\u3002\u540c\u65f6\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5b57\u7b26\u4e32\u62fc\u63a5\u7684\u65b9\u5f0f\u5c06\u4e24\u4e2a\u5b57\u7b26\u4e32\u8fde\u63a5\u8d77\u6765\u3002<\/p>\n<p><strong>Q: \u5982\u4f55\u5728 JavaScript \u4e2d\u5b9e\u73b0\u51cf\u6cd5\u8fd0\u7b97\uff1f<\/strong><\/p>\n<p>A: \u5728 JavaScript \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u51cf\u53f7\uff08-\uff09\u7b26\u53f7\u6765\u5b9e\u73b0\u51cf\u6cd5\u8fd0\u7b97\u3002\u901a\u8fc7\u5c06\u7b2c\u4e00\u4e2a\u6570\u5b57\u51cf\u53bb\u7b2c\u4e8c\u4e2a\u6570\u5b57\uff0c\u53ef\u4ee5\u5f97\u5230\u5b83\u4eec\u7684\u5dee\u503c\u3002\u8fd9\u4e2a\u64cd\u4f5c\u4e5f\u9002\u7528\u4e8e\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528\u51cf\u53f7\u4ece\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u53bb\u6389\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002<\/p>\n<p><strong>Q: \u5728 JavaScript \u4e2d\u5982\u4f55\u5b9e\u73b0\u4e58\u6cd5\u548c\u9664\u6cd5\u8fd0\u7b97\uff1f<\/strong><\/p>\n<p>A: \u5728 JavaScript \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e58\u53f7\uff08*\uff09\u7b26\u53f7\u6765\u5b9e\u73b0\u4e58\u6cd5\u8fd0\u7b97\u3002\u901a\u8fc7\u5c06\u4e24\u4e2a\u6570\u5b57\u76f8\u4e58\uff0c\u53ef\u4ee5\u5f97\u5230\u5b83\u4eec\u7684\u4e58\u79ef\u3002\u540c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u9664\u53f7\uff08\/\uff09\u7b26\u53f7\u6765\u5b9e\u73b0\u9664\u6cd5\u8fd0\u7b97\u3002\u5c06\u7b2c\u4e00\u4e2a\u6570\u5b57\u9664\u4ee5\u7b2c\u4e8c\u4e2a\u6570\u5b57\uff0c\u53ef\u4ee5\u5f97\u5230\u5b83\u4eec\u7684\u5546\u3002\u5728\u9664\u6cd5\u8fd0\u7b97\u4e2d\u9700\u8981\u6ce8\u610f\u9664\u6570\u4e0d\u80fd\u4e3a\u96f6\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728JavaScript\u7f16\u7a0b\u4e2d\uff0c\u5b9e\u73b0\u52a0\u51cf\u4e58\u9664\u8fd0\u7b97\u662f\u57fa\u7840\u64cd\u4f5c\u7684\u6838\u5fc3\u90e8\u5206\u3002\u8fd9\u4e9b\u57fa\u672c\u7684\u7b97\u672f\u8fd0\u7b97\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528JavaSc [&hellip;]","protected":false},"author":3,"featured_media":170757,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/170747"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=170747"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/170747\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/170757"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=170747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=170747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=170747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}