There are two methods I am using to create an array.
- The first method involves creating an array in a traditional way.
- The second method involves creating an array using backticks function.
let array=["1234"];
function createArrayByBakticks(obj)
{
return obj;
}
let backtickArray = createArrayByBakticks `1234`;// it's responding an array
console.log(array); //1st way and it returns an array
console.log(backtickArray ); //2nd way and it returns the same array
backtickArray.push(1);// but it's throwing an error while trying to push a new value.
// Error: Uncaught TypeError: Cannot add property 1, object is not extensible
console.log(backtickArray);
Both of the methods mentioned above return data as an array. However, the second array created by backticks does not support the built-in functions of arrays. WHY? What is the difference between these two methods??