Why arguments is not defined in arrow function in ES6? [duplicate] - javascript

This question already has answers here:
Official information on `arguments` in ES6 Arrow functions?
(2 answers)
Do ES6 arrow functions have their own arguments or not? [duplicate]
(4 answers)
Closed 7 years ago.
For this code
var sum = () => {console.log(arguments); ... }
sum(2, 3)
Get error Uncaught ReferenceError: arguments is not defined.
Why arguments is not defined in arrow function?

Related

Unexpected hehaviour when defining vairables [duplicate]

This question already has answers here:
JavaScript 'hoisting' [duplicate]
(5 answers)
Javascript function scoping and hoisting
(18 answers)
What are the precise semantics of block-level functions in ES6?
(2 answers)
Closed 1 year ago.
I have come across a very strange JavaScript code. Its execution result is completely different from what I expected. I want to know why.
var  a  =  1999;
{
console.log(a);
a  =  2020;
function  a()  {}
a  =  2021;
}
console.log(a); //Why 2020?

How are these methods of writing functions different? [duplicate]

This question already has answers here:
How does this object method definition work without the "function" keyword?
(2 answers)
ES6 Object Literal Syntax for Methods
(1 answer)
Closed 2 years ago.
I have code that has the following functions written:
testing: function() {
///
}
what is the difference of writing it as :
testing() {
///
}
Do they mean the same thing and have the same purpose?

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)})()

Difference between `function(event)` and `function = event =>` [duplicate]

This question already has answers here:
Are 'Arrow Functions' and 'Functions' equivalent / interchangeable?
(4 answers)
Closed 4 years ago.
I am confused in trying to understand the function event object.
How does function(event) differ from function = event => in a code like the one below?
functionName(event) {
// code
}
Check our this article will cover arrow Functions for Beginners Javascript. Arrow functions are a new ES6 syntax for writing JavaScript functions.

Confused about this in ES6. It's equal to window [duplicate]

This question already has answers here:
Are 'Arrow Functions' and 'Functions' equivalent / interchangeable?
(4 answers)
Closed 5 years ago.
I have this function call in jQuery:
image.save(comment);
and I've defined the save function like this:
Image.prototype.save = association => {
debugger;
this
}
How do I get this to equal the recipient of the function call which is image? Right now at the debugger, it equals the window object.
Do not use arrow functions
Arrow functions have a lexical this; its value is determined by the surrounding scope.
Image.prototype.save = function(association){
debugger;
this
}

Categories

Resources