JavaScript 15 ๐งฌ Arrow functions
a - arrow functions introduction
Arrow functions in JavaScript provide a concise syntax for writing functions
They are part of the ECMAScript 2015 (ES6) specification.
They offer several advantages such as more compact syntax, lexical this binding, and no need for the function keyword.
They don't have their own bindings to this, arguments, or super, and should not be used as methods.
They cannot be used as constructors and cannot use yield. They cannot be created as generator functions
syntax:
const functionName = (parameters) = {
// function body
};
The parantheses around parameters can only be omitted if there is a single parameter
const squareRoot = a = {
return a*a
};
Curly braces can only be omitted if the function returns an expression
const squareRoot = a = return a*a
b - Arrow function examples
Example 1 โ concise syntax, omit parentheses
Example 2 โ concise syntax, omit curly braces
Example 3 โ Basic syntax
Example 4 โ with multiple statements
Example 5 โ `this` correctly refers to the person object
Example 6 โ arrow function in array method
Example 7 โ Arrow functions cannot be used as constructors. TypeError: Foo is not a constructor
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!