'Turning an arrow function to a regular function javascript
i have to turn an arrow function to a regular one. The problem is that the arrow function is pretty different from those i'm used to work with hence harder to transform. I need your help please. Here is the arrow function followed by the regular function i tried to code. The functions :
(name) => {
`Bonjour, ${name} ! Comment vas-tu ?`;
}
taille = () =>
{
function(name)
{
return `Bonjour, ${name} ! Comment vas-tu?`;
}
Solution 1:[1]
The equivalent regular function is almost identical to the arrow function.
function(name) {
`Bonjour, ${name} ! Comment vas-tu?`;
}
When an arrow function's body is surrounded by {}, it's the same as the body of a regular function. The differences between these types of arrow and regular functions are related to the scope of this and the availability of the special variable arguments, but these are not relevant in your example.
Note that this function is not very useful, since the string is never returned.
An arrow function only has an implicit return if the body is not surrounded by {}. Your regular function is equivalent to this:
(name) => `Bonjour, ${name} ! Comment vas-tu ?`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Barmar |
