More JS Interview Questions

const myArray = [1,2,3,4,5]// mapping with an anonymous callback functionconst myArray = [1,2,3,4,5]// mapping with an anonymous callback functionmyArray.map((item) => {return item*10})
// output: [ 10, 20, 30, 40, 50 ]
// performing the same mapping with the same function, only as a named function that has been declared beforehandconst multiplyByTen = (item) => {
return item*10
}
myArray.map(multiplyByTen)
// output is the same: [ 10, 20, 30, 40, 50 ]
function Person(){return 'hello, person!'}
console.log(person)// output:Person {} // new Person object has been created
// an array of people object we wish to iterate over
const people = [
{
firstName: 'Sarah',
lastName: 'Jones',
birthDate: 'Jan 5, 1925',
gender: 'female'
},
{
firstName: 'Sue',
lastName: 'Long',
birthDate: 'Jan 6, 1925',
gender: 'female'
},
{
firstName: 'John',
lastName: 'Doe',
birthDate: 'Jan 7, 1925',
gender: 'male'
},
{
firstName: 'Jimmy',
lastName: 'Doe',
birthDate: 'Jan 8, 1925',
gender: 'male'
},
{
firstName: 'Yusuf',
lastName: 'Ahmed',
birthDate: 'Jan 19, 1925',
gender: 'male'
}
]
// a function with a for/in loop inside a for/of loop will log each of the keys and values for all 5 person objects when our array of objects (people) is passed to it.const loopOverObjArray = (arr) => {
for(let obj of arr) {
for(let key in obj) {
console.log(`The key is ${key}, and the value is ${obj[key]}`)
}
}
}
loopOverObjArray(people)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Michael Fares

Michael Fares

10 Followers

I am a Frontend Web Developer, Educator, Lifelong autodidact, 3rd Culture Kid, and Citizen of the World.