Common JS Interview Stuff
by adil_invideo
HTML
<div class="parent">
<div class="child">
</div>
</div>
CSS
.parent {
width: 200px;
height: 200px;
background: red;
display: flex;
align-items: center;
justify-content: center;
}
.child {
width: 50px;
height: 50px;
background: blue;
}
JavaScript
/*******************/
console.log("a");
console.log("b");
setTimeout(() => {
console.log("c");
}, 0)
console.log("d");
/* **** Recreating MAP******* */
const numbers = [1, 2, 3, 4, 5];
Array.prototype.map = function(callback){
let result = [];
for(i = 0; i < this.length; i++ ){
result.push(callback(this[i]));
}
return result;
};
const result = numbers.map(num => num * 10);
console.log(result);
/**** Arbaaz's example */
const arr = [10, 12, 15, 21];
for(var i = 0; i< arr.length; i++) {
setTimeout(() => {
console.log(`Index: ${i}, element: ${arr[i]}`);
}, 3000);
};