{"id":1909,"date":"2023-03-25T14:26:38","date_gmt":"2023-03-25T06:26:38","guid":{"rendered":""},"modified":"2023-03-25T14:26:38","modified_gmt":"2023-03-25T06:26:38","slug":"ES6 \u8fd0\u7b97\u7b26","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1909.html","title":{"rendered":"ES6 \u8fd0\u7b97\u7b26"},"content":{"rendered":"
\n
Operators: \u8d1f\u8d23\u5bf9\u64cd\u4f5c\u6570\u8fdb\u884c\u4e00\u4e9b\u64cd\u4f5c<\/span> \u7b97\u672f\u8fd0\u7b97\u7b26<\/span> <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n
\n \u64cd\u4f5c\u6570: \u4ee3\u8868\u6570\u636e\u3002<\/span> <\/p>\n\u8fd0\u7b97\u7b26\u7684\u7c7b\u578b<\/h2>\n
\n \u5173\u7cfb\u8fd0\u7b97\u7b26<\/span>
\n \u903b\u8f91\u8fd0\u7b97\u7b26<\/span>
\n \u8d4b\u503c\u8fd0\u7b97\u7b26<\/span>
\n \u6309\u4f4d\u8fd0\u7b97\u7b26<\/span>
\n \u7c7b\u578b\u8fd0\u7b97\u7b26<\/span>
\n \u6742\u9879\u64cd\u4f5c\u5458<\/span> <\/p>\n\u7b97\u672f\u8fd0\u7b97\u7b26<\/h3>\n
\n\n
\n \u8fd0\u8425\u5546<\/td>\n \u51fd\u6570<\/td>\n<\/tr>\n \n +(\u6dfb\u52a0)<\/td>\n \u8fd4\u56de\u64cd\u4f5c\u6570\u7684\u603b\u548c<\/td>\n<\/tr>\n \n -(\u51cf\u6cd5)<\/td>\n \u8fd4\u56de\u64cd\u4f5c\u6570\u4e4b\u95f4\u7684\u5dee\u503c<\/td>\n<\/tr>\n \n *(\u4e58\u6cd5)<\/td>\n \u5b83\u8fd4\u56de\u64cd\u4f5c\u6570\u503c\u7684\u4e58\u79ef\u3002<\/td>\n<\/tr>\n \n \/(\u90e8\u95e8)<\/td>\n \u7528\u4e8e\u9664\u6cd5\uff0c\u8fd4\u56de\u5546\u3002<\/td>\n<\/tr>\n \n %(\u6a21\u6570)<\/td>\n \u5b83\u8fd8\u6267\u884c\u9664\u6cd5\u5e76\u8fd4\u56de\u4f59\u6570\u3002<\/td>\n<\/tr>\n \n ++(\u589e\u91cf)<\/td>\n \u5c06\u53d8\u91cf\u7684\u503c\u52a0\u4e00\u3002<\/td>\n<\/tr>\n \n -(\u9012\u51cf)<\/td>\n \u5c06\u53d8\u91cf\u7684\u503c\u51cf\u4e00\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n var <\/span>x = 30; \nvar <\/span>y = 20 ;\nconsole.log<\/span>(\"Addition: \"<\/span> + (x + y) );\nconsole.log<\/span>(\"Subtraction: \"<\/span> + (x-y) );\nconsole.log<\/span>(\"Multiplication: \"<\/span> + (x * y) );\nconsole.log<\/span>(\"The Division will give you the quotient: \"<\/span> + (x \/ y) );\nconsole.log<\/span>(\"Modulus will give you the Remainder: \"<\/span> + (x % y) );\n\/\/ pre-increment <\/span>\nconsole.log<\/span>(\"Value of x after pre-increment: \"<\/span> + (++x) );\n\/\/ post-increment <\/span>\nconsole.log<\/span>(\"Value of x after post-increment: \"<\/span> + (x++) );\n\/\/ pre-decrement <\/span>\nconsole.log<\/span>(\"Value of y after pre-decrement: \"<\/span> + (--y) );\n\/\/ post-decrement <\/span>\nconsole.log<\/span>(\"Value of y after post-decrement: \"<\/span> + (y--) );<\/pre>\n
Addition : 50\nSubtraction: 10\nMultiplication: 600\nThe division will give you the quotient: 1.5\nModulus will give you the Remainder: 10\nValue of x after pre-increment: 31\nValue of x after post-increment: 31\nValue of y after pre-decrement: 19\nValue of y after post-decrement: 19<\/pre>\n
\u5173\u7cfb\u8fd0\u7b97\u7b26<\/h3>\n
\n\n
\n \u64cd\u4f5c\u5458<\/td>\n \u529f\u80fd<\/td>\n<\/tr>\n \n >(\u5927\u4e8e)<\/td>\n \u5982\u679c\u5de6\u64cd\u4f5c\u6570\u5927\u4e8e\u53f3\u64cd\u4f5c\u6570\u5219\u8fd4\u200b\u200b\u56de\u771f\uff0c\u5426\u5219\u8fd4\u56de\u5047\u3002<\/td>\n<\/tr>\n \n <(\u5c0f\u4e8e)<\/td>\n \u5982\u679c\u5de6\u64cd\u4f5c\u6570\u5c0f\u4e8e\u53f3\u64cd\u4f5c\u6570\u5219\u8fd4\u200b\u200b\u56de\u771f\uff0c\u5426\u5219\u8fd4\u56de\u5047\u3002 <\/td>\n<\/tr>\n \n >=(\u5927\u4e8e\u6216\u7b49\u4e8e)<\/td>\n \u5982\u679c\u5de6\u64cd\u4f5c\u6570\u5927\u4e8e\u6216\u7b49\u4e8e\u53f3\u64cd\u4f5c\u6570\u5219\u8fd4\u200b\u200b\u56de\u771f\uff0c\u5426\u5219\u8fd4\u56de\u5047\u3002<\/td>\n<\/tr>\n \n <=(\u5c0f\u4e8e\u6216\u7b49\u4e8e)<\/td>\n \u5982\u679c\u5de6\u64cd\u4f5c\u6570\u5c0f\u4e8e\u6216\u7b49\u4e8e\u53f3\u64cd\u4f5c\u6570\u5219\u8fd4\u200b\u200b\u56de\u771f\uff0c\u5426\u5219\u8fd4\u56de\u5047\u3002 <\/td>\n<\/tr>\n \n ==(\u5e73\u7b49)<\/td>\n \u5982\u679c\u4e24\u4e2a\u64cd\u4f5c\u6570\u7684\u503c\u76f8\u540c\u5219\u8fd4\u56de\u771f\uff0c\u5426\u5219\u8fd4\u56de\u5047\u3002<\/td>\n<\/tr>\n \n !=(\u4e0d\u7b49\u4e8e)<\/td>\n \u5982\u679c\u64cd\u4f5c\u6570\u7684\u503c\u4e0d\u540c\u5219\u8fd4\u56de\u771f\uff0c\u5426\u5219\u8fd4\u56de\u5047\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n var <\/span>x = 20; \nvar <\/span>y = 15; \nconsole.log<\/span>(\"Value of x: \"<\/span> + x); \nconsole.log<\/span>(\"Value of y: \"<\/span> + y); \nvar <\/span>result = x > y; \nconsole.log<\/span>(\"x is greater than y: \"<\/span> + result); \nresult = x < y; \nconsole.log<\/span>(\"x is smaller than y: \"<\/span> + result); \nresult = x >= y; \nconsole.log<\/span>(\"x is greater than or equal to y: \"<\/span> + result); \nresult = x <= y; \nconsole.log<\/span>(\"x is smaller than or equal to y: \"<\/span> + result); \nresult = x == y; \nconsole.log<\/span>(\"x is equal to y: \"<\/span> + result); \nresult = x != y; \nconsole.log<\/span>(\"x not equal to y: \"<\/span> + result);<\/pre>\n
Value of x: 20\nValue of y: 15\nx is greater than y: true<\/span><\/span>\nx is smaller than y: false<\/span>\nx is greater than or equal to y: true<\/span><\/span>\nx is smaller than or equal to y: false<\/span>\nx is equal to y: false<\/span>\nx not equal to y: true<\/span><\/span><\/pre>\n
\u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n
\n\n
\n \u8fd0\u8425\u5546<\/td>\n \u8bf4\u660e<\/td>\n<\/tr>\n \n &&(\u903b\u8f91\u4e0e)<\/td>\n \u5982\u679c\u6240\u6709\u4e0e && \u7ec4\u5408\u7684\u5173\u7cfb\u8bed\u53e5\u90fd\u4e3a\u771f\uff0c\u5219\u6b64\u8fd0\u7b97\u7b26\u8fd4\u56de\u771f\uff0c\u5426\u5219\u8fd4\u56de\u5047\u3002<\/td>\n<\/tr>\n \n ||(\u903b\u8f91\u6216)<\/td>\n \u5982\u679c\u81f3\u5c11\u6709\u4e00\u4e2a\u4e0e || \u7ec4\u5408\u7684\u5173\u7cfb\u8bed\u53e5\uff0c\u5219\u6b64\u8fd0\u7b97\u7b26\u8fd4\u56de true\u4e3a\u771f\uff0c\u5426\u5219\u8fd4\u56de\u5047\u3002<\/td>\n<\/tr>\n \n !(\u903b\u8f91\u975e)<\/td>\n \u5b83\u8fd4\u56de\u8bed\u53e5\u7ed3\u679c\u7684\u5012\u6570\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n var <\/span>x = 30; \nvar <\/span>y = 80; \nconsole.log<\/span>(\"Value of x = \"<\/span> + x );\nconsole.log<\/span>(\"Value of y = \"<\/span> + y );\nvar <\/span>result = ((x < 40) && (y <= 90)); \nconsole.log<\/span>(\"(x < 40) && (y <= 90): \"<\/span>, result); \nvar <\/span>result = ((x == 50) ||<\/span> (y > 80)); \nconsole.log<\/span>(\"(x == 50) |<\/span>| (y > 80): \"<\/span>, result); \nvar <\/span>result = !((x > 20) && (y >= 80)); \nconsole.log<\/span>(\"!((x > 20) && (y >= 80)): \"<\/span>, result);<\/pre>\n
Value of x = 30\nValue of y = 80\n(x < 40) && (y <= 90): true<\/span><\/span>\n(x == 50) ||<\/span> (y > 80): false<\/span>\n!((x > 20) && (y >= 80)): false<\/span><\/pre>\n
\u8d4b\u503c\u8fd0\u7b97\u7b26<\/h3>\n
\n\n
\n \u8fd0\u8425\u5546<\/td>\n \u51fd\u6570<\/td>\n<\/tr>\n \n =(\u7b80\u5355\u8d4b\u503c)<\/td>\n \u5b83\u53ea\u662f\u5c06\u53f3\u64cd\u4f5c\u6570\u7684\u503c\u8d4b\u7ed9\u5de6\u64cd\u4f5c\u6570<\/td>\n<\/tr>\n \n +=(\u6dfb\u52a0\u548c\u5206\u914d)<\/td>\n \u6b64\u8fd0\u7b97\u7b26\u5c06\u53f3\u64cd\u4f5c\u6570\u7684\u503c\u4e0e\u5de6\u64cd\u4f5c\u6570\u7684\u503c\u76f8\u52a0\uff0c\u5e76\u5c06\u7ed3\u679c\u8d4b\u7ed9\u5de6\u64cd\u4f5c\u6570\u3002<\/td>\n<\/tr>\n \n -=(\u51cf\u6cd5\u548c\u8d4b\u503c)<\/td>\n \u6b64\u8fd0\u7b97\u7b26\u4ece\u5de6\u64cd\u4f5c\u6570\u7684\u503c\u4e2d\u51cf\u53bb\u53f3\u64cd\u4f5c\u6570\u7684\u503c\uff0c\u5e76\u5c06\u7ed3\u679c\u8d4b\u7ed9\u5de6\u64cd\u4f5c\u6570\u3002<\/td>\n<\/tr>\n \n *=(\u4e58\u6cd5\u548c\u8d4b\u503c)<\/td>\n \u6b64\u8fd0\u7b97\u7b26\u5c06\u53f3\u64cd\u4f5c\u6570\u7684\u503c\u4e58\u4ee5\u5de6\u64cd\u4f5c\u6570\u7684\u503c\uff0c\u5e76\u5c06\u7ed3\u679c\u8d4b\u7ed9\u5de6\u64cd\u4f5c\u6570\u3002<\/td>\n<\/tr>\n \n \/=(\u5206\u800c\u6cbb\u4e4b)<\/td>\n \u6b64\u8fd0\u7b97\u7b26\u5c06\u53f3\u64cd\u4f5c\u6570\u7684\u503c\u9664\u4ee5\u5de6\u64cd\u4f5c\u6570\u7684\u503c\uff0c\u5e76\u5c06\u7ed3\u679c\u8d4b\u7ed9\u5de6\u64cd\u4f5c\u6570\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n var <\/span>x = 20; \nvar <\/span>y = 40; \nx = y;\nconsole.log<\/span>(\"After assignment the value of x is: \"<\/span> + x); \nx += y; \nconsole.log<\/span>(\"x+=y: \"<\/span> + x); \nx-= y; \nconsole.log<\/span>(\"x-=y: \"<\/span> + x); \nx *= y; \nconsole.log<\/span>(\"x*=y: \"<\/span> + x); \nx \/= y; \nconsole.log<\/span>(\"x\/=y: \"<\/span> + x); \nx %= y; \nconsole.log<\/span>(\"x%=y: \"<\/span> + x);<\/pre>\n
After assignment the value of x is: 40 \nx+=y: 80\nx-=y: 40\nx*=y: 1600\nx\/=y: 40\nx%=y: 0<\/pre>\n
\u6309\u4f4d\u8fd0\u7b97\u7b26<\/h3>\n
\n\n
\n \u64cd\u4f5c\u5458<\/td>\n \u8bf4\u660e<\/td>\n<\/tr>\n \n \u6309\u4f4d\u4e0e(&)<\/td>\n \u5b83\u5c06\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570\u7684\u6bcf\u4e00\u4f4d\u4e0e\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u6570\u7684\u76f8\u5e94\u4f4d\u8fdb\u884c\u6bd4\u8f83\u3002\u5982\u679c\u4e24\u4e2a\u4f4d\u90fd\u4e3a 1\uff0c\u5219\u7ed3\u679c\u4f4d\u5c06\u8bbe\u7f6e\u4e3a 1\uff0c\u5426\u5219\u5c06\u8bbe\u7f6e\u4e3a 0\u3002<\/td>\n<\/tr>\n \n \u6309\u4f4d\u6216(|)<\/td>\n \u5b83\u5c06\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570\u7684\u6bcf\u4e00\u4f4d\u4e0e\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u6570\u7684\u76f8\u5e94\u4f4d\u8fdb\u884c\u6bd4\u8f83\u3002\u5982\u679c\u4e24\u4e2a\u4f4d\u90fd\u4e3a 0\uff0c\u5219\u7ed3\u200b\u200b\u679c\u4f4d\u5c06\u8bbe\u7f6e\u4e3a 0\uff0c\u5426\u5219\u5c06\u8bbe\u7f6e\u4e3a 1\u3001<\/td>\n<\/tr>\n \n \u6309\u4f4d\u5f02\u6216(^)<\/td>\n \u5b83\u9700\u8981\u4e24\u4e2a\u64cd\u4f5c\u6570\uff0c\u5e76\u5bf9\u4e24\u4e2a\u64cd\u4f5c\u6570\u7684\u6bcf\u4e00\u4f4d\u8fdb\u884c\u5f02\u6216\u3002\u5982\u679c\u4e24\u4e2a\u4f4d\u90fd\u4e0d\u540c\uff0c\u5219\u8fd4\u56de 1\uff0c\u5426\u5219\u8fd4\u56de 0\u3002<\/td>\n<\/tr>\n \n \u6309\u4f4d\u975e(~)<\/td>\n \u5b83\u7ffb\u8f6c\u5176\u64cd\u4f5c\u6570\u7684\u4f4d\uff0c\u53730\u53d8\u4e3a1\uff0c1\u53d8\u4e3a0\u3002<\/td>\n<\/tr>\n \n \u5de6\u79fb(<<)<\/td>\n \u5b83\u5c06\u5de6\u64cd\u4f5c\u6570\u7684\u503c\u5411\u5de6\u79fb\u52a8\u53f3\u64cd\u4f5c\u6570\u6307\u5b9a\u7684\u4f4d\u6570\u3002<\/td>\n<\/tr>\n \n \u7b26\u53f7\u4f20\u64ad\u53f3\u79fb(>>)<\/td>\n \u5b83\u5c06\u5de6\u64cd\u4f5c\u6570\u7684\u503c\u5411\u53f3\u79fb\u52a8\u53f3\u64cd\u4f5c\u6570\u6307\u5b9a\u7684\u4f4d\u6570\u3002\u8fd9\u662f\u7b26\u53f7\u4f20\u64ad\uff0c\u56e0\u4e3a\u6211\u4eec\u4ece\u5de6\u8fb9\u6dfb\u52a0\u7684\u4f4d\u53d6\u51b3\u4e8e\u6570\u5b57\u7684\u7b26\u53f7(0 \u8868\u793a\u6b63\uff0c1 \u8868\u793a\u8d1f)\u3002 <\/td>\n<\/tr>\n \n \u96f6\u586b\u5145\u53f3\u79fb<\/td>\n \u5b83\u63a5\u53d7\u4e24\u4e2a\u64cd\u4f5c\u6570\u3002\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570\u6307\u5b9a\u6570\u5b57\uff0c\u4e00\u4e2and \u7b2c\u4e8c\u4e2a\u8fd0\u7b97\u7b26\u786e\u5b9a\u8981\u79fb\u4f4d\u7684\u4f4d\u6570\u3002\u6bcf\u4e00\u4f4d\u90fd\u5411\u53f3\u79fb\u52a8\uff0c\u6ea2\u51fa\u7684\u4f4d\u5c06\u88ab\u4e22\u5f03\u3002\u56e0\u4e3a0\u4f4d\u662f\u4ece\u5de6\u8fb9\u6dfb\u52a0\u7684\uff0c\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u5b83\u662f\u4e00\u4e2a\u96f6\u586b\u5145\u53f3\u79fb\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n var <\/span>x = 70; \/* 70 = 0100 0110 *\/\nvar <\/span>y = 80; \/* 80 = 0101 0000 *\/\nvar <\/span>res = 0;\nconsole.log<\/span>(\"Value of 70 in binary 0100 0110\"<\/span> );\nconsole.log<\/span>(\"Value of 80 in binary 0101 0000\"<\/span> );\nres = x & y; \/* 64 = 0100 0000 *\/\nconsole.log<\/span>(\"Value of x & y = %d\\n\"<\/span>, res );\nres = x | y; \/* 86 = 0101 0110 *\/\nconsole.log<\/span>(\"Value of x |<\/span> y = %d\\n\", res );\nres = x ^ y; \/* 22 = 0001 0110 *\/\nconsole.log<\/span>(\"Value of x ^ y = %d\\n\"<\/span>, res );\nres = ~x; \/*-71 =-0100 0111 *\/\nconsole.log<\/span>(\"Value of ~ x = %d\\n\"<\/span>, res );\nres = x << 2; \/* 280 = 1000 11000 *\/\nconsole.log<\/span>(\"Value of x << 2 = %d\\n\"<\/span>, res );\nres = x >> 2; \/* 17 = 0001 0001 *\/\nconsole.log<\/span>(\"Value of x >> 2 = %d\\n\"<\/span>, res );<\/pre>\n
Value of 70 in binary 0100 0110\nValue of 80 in binary 0101 0000\nValue of x & y = 64\nValue of x | y = 86\nValue of x ^ y = 22\nValue of ~ x =-71\nValue of x << 2 = 280\nValue of x >> 2 = 17<\/pre>\n
\u6742\u9879\u8fd0\u7b97\u7b26<\/h3>\n
\n\n
\n \u8fd0\u8425\u5546<\/td>\n \u8bf4\u660e<\/td>\n<\/tr>\n \n +(\u8fde\u63a5\u8fd0\u7b97\u7b26)<\/td>\n \u5b83\u9002\u7528\u4e8e\u5b57\u7b26\u4e32\u5e76\u5c06\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\u9644\u52a0\u5230\u7b2c\u4e00\u4e2a\u3002<\/td>\n<\/tr>\n \n -(\u5426\u5b9a\u8fd0\u7b97\u7b26)<\/td>\n \u5b83\u6539\u53d8\u4e86\u503c\u7684\u7b26\u53f7\u3002<\/td>\n<\/tr>\n \n \uff1f(\u6761\u4ef6\u8fd0\u7b97\u7b26)<\/td>\n \u7528\u4e8e\u8868\u793a\u6761\u4ef6\u8868\u8fbe\u5f0f\u3002\u5b83\u4e5f\u88ab\u79f0\u4e3a\u4e09\u5143\u8fd0\u7b97\u7b26\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u5426\u5b9a\u64cd\u4f5c\u7b26(-)<\/h3>\n
var <\/span>num1 = 80;\nvar <\/span>num2 =-num1;\nconsole.log<\/span>(\"Value of num1 = \"<\/span> +num1); \/\/ It will give 80<\/span>\nconsole.log<\/span>(\"Value of num2 = \"<\/span> +num2); \/\/ It will give-80<\/span><\/pre>\n
Value of num1 = 80\nValue of num2 =-80<\/pre>\n
\u8fde\u63a5\u8fd0\u7b97\u7b26(+)<\/h3>\n
var <\/span>str1 = 'Hello'<\/span> +