1. Javascript Hoisting ?
Hoisting is JavaScript’s default behavior of moving declarations to the top of their containing scope.
e.g.,
var x, y, z; // declaring function-scoped variables
let a, b, c; // declaring block-scoped variables
const u, v, w; // declaring block-scoped constants
2.Difference between Splice and Slice
The splice() method returns the removed item(s) in an array and slice() method returns the selected element(s) in an array, as a new array object.
Splice :
var array=[1,2,3,4,5];
console.log(array.splice(2));
// shows [3, 4, 5], returned removed item(s) as a new array object.
console.log(array);
// shows [1, 2], original array altered.
This will return [3,4,5]. The original array is affected resulting in array being [1,2].
Slice :
var array=[1,2,3,4,5]
console.log(array.slice(2));
// shows [3, 4, 5], returned selected element(s).
console.log(array);
// shows [1, 2, 3, 4, 5], original array remains intact.
This will return [3,4,5]. The original array is NOT affected with resulting in array being [1,2,3,4,5].
The splice() method changes the original array and slice() method doesn’t change the original array.
1.The splice() method returns the removed item(s) in an array and slice() method returns the selected element(s) in an array, as a new array object.
2. The splice() method changes the original array and slice() method doesn’t change the original array.