1. Difference between slice() and splice() methods:
slice() method can take only two arguments. The first parameter of the slice() method is the starting index and the next one is the ending index. It’s doesn’t change the main array it returns a new array.
On the other hand the
splice() method can take several parameters. The first one is the starting point and the next one is the number of items you want to remove and after that, you can pass as a parameter those items you want to add new. It will return you deleted items and you will find your main array as modified.
array.splice(startIndex, totalItem, item 1, item 2, …..item n)
2. What is closure()
If I return or use any function from another function then it’ll create a closed environment and if the inner function which one we will return, that function use any outer variable then it’ll save a reference value of an external variable and this is called
3. What is Hoisting
4. (== vs ===) Difference between double equal and Triple equal
Triple equal (===) means it will check the value and also data type if both are matched then it will return true if anyone doesn’t match it will return false.
On the other hand double equal (==) means it will check only value, not the data type. It will firstly make data type correction based upon the values of variables and then check the variable's value.
5. Null vs Undefined
- If you want to access any objects property that doesn’t exist there then it will return undefined.
- If you want to access any variable without initializing then you will get undefined.
- If you don't pass the function's parameter which you used that time you will get undefined
- If you want to access any value from an array that does not exist.
- And you can also set a value as undefined but which is not recommended.
And many other ways you can get undefined.
But you don’t get any null value by default. You have to set the value explicitly as a null when you needed.
6. Truthy vs Falsy
In programming, there are two types of boolean value one is true and another is false.
The truthy values are given below:
The falsy values are :
7. Callback Function
If you pass any function as a parameter of another function it’s called callback function. An example is given below: