Important sites - Omni Calculator.
Using forEach you can not return anything.
If you try to return anything using forEach you will get undefined, which tells that forEach can not return any value.
To Overcome that problem we have something called as mapping.
Using mapping one can return anything.
one more difference is that we can not do chaining using forEach where as we can use map, filter etc to achieve chaining.
There are methods in javascript that modify the original array and there are certain methods in javascript that make a copy of the original array and then make any changes to it.
Methods that modify the original array are :
- push().
- pop().
- shift().
- unshift().
- splice().
- sort().
- reverse().
Methods that make a copy of the original array are :
- concat().
- slice().
- map().
- filter().
- reduce().
- flatMap().
const originalArray = [1, 2, 3, 4, 5];
const copiedArray = [...originalArray];
copiedArray.push(6);
if(copiedArray === originalArray) { console.log("The original array was modified"); } else { console.log("The origninal array was not modified"); }
-
innerText only returns the text within the tags.
-
innerHTML returns tags along with all the children tags present within the parent element.
This is inner Text
const myElement = document.getElementById("myDiv"); console.log(myElement.innerText)
--> gives output as This is inner Text
console.log(myElement.innerHTML)
--> gives output as
This is inner Text
In javascript normal code executes line by line. what if some line of code takes some more time to execute?
Example: c console.log("task1")
console.log("task3")
setTimeout(() => { console.log("task2"); }, 1000);
Here we want the javascript to wait until and unless a certain task is done !!!
Thats where Promises come into picture!!
In real world you can say: Although it is not my general phenomena but I promise I will wait untill and unless the task is completed and then I will move to execute the next task.