mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix(curriculum): update arrow syntax code examples for step 11 of music player project (#53779)
This commit is contained in:
+8
-15
@@ -7,29 +7,22 @@ dashedName: step-11
|
||||
|
||||
# --description--
|
||||
|
||||
Now you need a way to display the songs in the UI. To do this, you'll create a `renderSongs` function using the arrow function syntax.
|
||||
Now you need a way to display the songs in the UI (User Interface). To do this, you'll create a `renderSongs` function using the arrow function syntax.
|
||||
|
||||
An arrow function is a shorter and more concise way to write functions in JavaScript. It's a <dfn>function expression</dfn>, which is a function that's assigned to a variable. To write an arrow function, you can use the following syntax:
|
||||
An arrow function is a shorter and more concise way to write functions in JavaScript. It's a <dfn>function expression</dfn>, which is a function that's assigned to a variable.
|
||||
|
||||
Here is an example of an arrow function with a single parameter and a single expression in the function body:
|
||||
|
||||
```js
|
||||
// Traditional function
|
||||
function add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
console.log(add(3, 5)); // Output: 8
|
||||
|
||||
// Arrow function
|
||||
const addArrow = (a, b) => {
|
||||
return a + b;
|
||||
const exampleArrowFunction = (param) => {
|
||||
return param
|
||||
};
|
||||
console.log(addArrow(3, 5)); // Output: 8
|
||||
```
|
||||
|
||||
If the function body consists of a single expression, you don't need the curly braces and the `return` keyword. This is called an `implicit return`:
|
||||
If the function body consists of a single expression, you can omit the curly braces and the `return` keyword. This is called an `implicit return`:
|
||||
|
||||
```js
|
||||
const addArrow = (a, b) => a + b;
|
||||
console.log(addArrow(3, 5)); // Output: 8
|
||||
const exampleArrowFunction = (param) => param;
|
||||
```
|
||||
|
||||
Use the arrow function syntax to create a `renderSongs` function that takes in `array` as its parameter.
|
||||
|
||||
Reference in New Issue
Block a user