fix(curriculum): update arrow syntax code examples for step 11 of music player project (#53779)

This commit is contained in:
Aaqib Javaid
2024-02-19 14:23:06 +01:00
committed by GitHub
parent 683b489094
commit 553ddd1ffa
@@ -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.