This question already has answers here:
What's the meaning of "=>" (an arrow formed from equals & greater than) in JavaScript?
(14 answers)
Closed 6 years ago.
Easy question for someone to answer, what happens in this typescript function?
getTweetCount = () => this.data.totalCount;
data.totalCount is of type number from a service.
getTweetCount = () => this.data.totalCount;
You are creating an "arrow function" that returns this.data.totalCount. There are lots of docs about arrow functions out there.
More
Arrow functions are also covered here : https://basarat.gitbooks.io/typescript/content/docs/arrow-functions.html
Related
This question already has answers here:
Spread Syntax ES6
(8 answers)
Closed 7 months ago.
I am trying to learn javascript but having trouble in the spread and rest operators.
Can't understand whats happening here how dose this take in the taxRate parameter like a singel number when we spred the itemsBought parameter
function addTaxToPrices (taxRate, ...itemsBought)
{
return(itemsBought.map(item => item*taxRate));
}
let ShoppingCart=addTaxToPrices(1.1,46,89,35,79);
console.log(ShoppingCart)
for my understanding it is nearly the same than if you do:
function addTaxToPrices (taxRate, itemsBought)
{
return(itemsBought.map(item => item*taxRate));
}
itemsBought = [46,89,35,79]
let ShoppingCart=addTaxToPrices(1.1,itemsBought);
console.log(ShoppingCart)
This question already has answers here:
Why doesn't my arrow function return a value?
(1 answer)
Curly Brackets in Arrow Functions
(3 answers)
When should I use a return statement in ES6 arrow functions
(6 answers)
Closed 1 year ago.
The following code works:
let check = checkingImages.every((item)=>item.classList.contains('matched'))
But this one doesn't:
let check = checkingImages.every((item)=>{
item.classList.contains('matched')
})
Can someone explain what's the reason for the second code not working, please?
This question already has answers here:
What does this symbol mean in JavaScript?
(1 answer)
What does curly brackets in the `var { ... } = ...` statements do?
(4 answers)
What do {curly braces} around javascript variable name mean [duplicate]
(1 answer)
Closed 4 years ago.
I was reading some JavaScript code and saw a line of code similar to this.
const {name, password, email} = user;
I tried searching around but could not figure out what this syntax is called so I am not able find the documentation. Is this a new JavaScript syntax? What is it called? What does it do exactly?
This question already has answers here:
What do multiple arrow functions mean in JavaScript?
(7 answers)
How does the spread syntax in ES6 JS work as a function argument?
(1 answer)
What are these three dots in React doing?
(23 answers)
Closed 5 years ago.
How does this work:
const invert = fn => (...args) => -fn(...args);
Specifically, what is happening with (...args). It behaves as if it is separating the arguments from the function after the first fat arrow, but I suspect there is a better, more specific, explanation. Thanks.
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'm not sure what this is called in Javascript:
exports.withLocalCallback = () => {
return [1, 2, 3].map(x => x + 1)
}
I haven't seen this before and I can't even think of a way to google it. Can someone explain what's happening here?
It's arrow functions, and they work almost the same as normal js functions, with the difference that 'this' is bound to the scope in which the function is defined. So you don't need to bind functions to access the correct object.
The difference is none if you don't need 'this', except is another syntax, which looks more like functional language functions.