What is "()=>{}" in js? [duplicate] - javascript

This question already has answers here:
What's the meaning of "=>" (an arrow formed from equals & greater than) in JavaScript?
(14 answers)
Closed 5 years ago.
I searched for
"()=>{} in js"
on Google
But it's not displaying relative results
What is it?

=> is a shortcut for an anonymous function. So that's just a function that does nothing. equivalent to:
function () { }

Related

Immediately executed anonymous function syntax ambiguity [duplicate]

This question already has answers here:
Immediate function using JavaScript ES6 arrow functions
(3 answers)
Why are parentheses required around JavaScript IIFE? [duplicate]
(3 answers)
Closed 3 years ago.
Why is the following a syntax error?
(()=>{console.log(1)}())
()=>{console.log(1)} is clearly(?) an expression that evaluates to a fat arrow function, and () "should" call it?
Presumably because it is ambiguous. What is the ambiguity?
Obviously, I realise the following works:
(()=>{console.log(1)})()

What does a fat arrow function followed by a closure do? [duplicate]

This question already has answers here:
What does the arrow function with a () after means? [duplicate]
(3 answers)
What's the meaning of "=>" (an arrow formed from equals & greater than) in JavaScript?
(14 answers)
Closed 4 years ago.
I just came across this code:
routes: routes.map(route => ({
Notice the arrow function being followed by a closure. Why are closures used here?
see this repo for reference: https://github.com/prograhammer/vue-pizza/blob/master/src/http/router.js#L33
It returns an object. The parenthesis is to denote that this is an object not a block.
() => {return {hello: 'world' } } === () => ({hello: 'world'})

Why use '{' and '}' to define a javascript variable [duplicate]

This question already has answers here:
Javascript object bracket notation ({ Navigation } =) on left side of assign
(5 answers)
What does this symbol mean in JavaScript?
(1 answer)
Closed 4 years ago.
I can't seem to find anything in the documentation to understand why the { and } characters are wrapped around variables on some examples I've seen. Can anyone example why we would do that?
For example:
const {app} = require('./app/app.js');

Number functions and other functions issue [duplicate]

This question already has answers here:
Calling the toFixed method on a number literal [duplicate]
(3 answers)
Why can't I access a property of an integer with a single dot?
(5 answers)
Closed 5 years ago.
Can someone logicaly explain why fallowing function return error
50.toFixed(2);
and this not
(50).toFixed(2);
Same happening with other similar number functions

what does !function() means in Javascript? [duplicate]

This question already has answers here:
What does the exclamation mark do before the function?
(8 answers)
Closed 9 years ago.
I can read and write some JavaScript, but today I came across a .js file starting with
!function() {
/*
code here
*/
}.call(window);
Question
what does ! infront of function means?
It returns "not" (!) of the result of a calling the anonymous function with a "this" of window.
Negating the result of .call(window). Not the function.

Categories

Resources