" Mean in JavaScript?The "=>" symbol, commonly known as the arrow function, is a concise syntax introduced in ECMAScript 6 for..."/> " Mean in JavaScript?The "=>" symbol, commonly known as the arrow function, is a concise syntax introduced in ECMAScript 6 for...">
Home >Web Front-end >JS Tutorial >What Does '=>' Mean in JavaScript Arrow Functions?
" Mean in JavaScript Arrow Functions? " />" Mean in JavaScript Arrow Functions? " />
The "=>" symbol, commonly known as the arrow function, is a concise syntax introduced in ECMAScript 6 for expressing function expressions. It offers several key advantages:
Arrow functions inherit the this value from their surrounding scope, unlike traditional functions. This eliminates the need for complex constructs like self = this to preserve this across nested functions.
Arrow functions are notably more compact than function expressions. Consider the following example:
// Old-style function expression var a2 = a.map(function(s) { return s.length; }); // Arrow function var a3 = a.map(s => s.length);
Both a2 and a3 will result in the same output ([31, 30, 31, 31]), but the arrow function is significantly more concise.
While arrow functions are supported in Node, browser support varies. As of December 12, 2017, they are supported in current versions of many popular browsers, including:
However, support for IE (through v. 11) and other lesser-known browsers is lacking. For the latest and most comprehensive compatibility information, refer to CanIUse.com.
The above is the detailed content of What Does '=>' Mean in JavaScript Arrow Functions?. For more information, please follow other related articles on the PHP Chinese website!