JS Basics Flashcards

1
Q

How to create a function in JS?

A
# 1. first option
let sample = function(name) {
    return name
};

sample(‘Name’) # returns ‘Name’

  1. second option
let sample = (name) => {
    return name
}
# 3. third option 
let sample = (name) => (name)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to use .map function?

A
arr = [1,2,3,4]
arr.map((num) => { return num * 2 })
# => [2, 4, 6, 8]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly