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’
- second option
let sample = (name) => { return name }
# 3. third option let sample = (name) => (name)
2
Q
How to use .map function?
A
arr = [1,2,3,4] arr.map((num) => { return num * 2 }) # => [2, 4, 6, 8]