Nalini1998 / Project_Public

MIT License
2 stars 0 forks source link

What will happen after running the following code? #540

Closed Nalini1998 closed 1 year ago

Nalini1998 commented 1 year ago

What will happen after running the following code?

const countries = ['Japan', 'Denmark', 'Mexico', 'Morocco'];
countries.shift();
console.log(countries); 
countries =  ['England', 'Mozambique', 'Cambodia', 'Peru']; 
console.log(countries); 

A. One array will be logged to the console followed by an error message

['Japan', 'Denmark', 'Mexico'];
TypeError: Assignment to constant variable

B. One array will be logged to the console followed by an error message

# ['Denmark', 'Mexico', 'Morocco'];
TypeError: Assignment to constant variable

C. Two arrays will be logged to the console:

['Denmark', 'Mexico', 'Morocco'];
['England', 'Mozambique', 'Cambodia', 'Peru'];

D. Two arrays will be logged to the console:

['Japan', 'Denmark', 'Mexico'];
['England', 'Mozambique', 'Cambodia', 'Peru'];
Nalini1998 commented 1 year ago

I chose B. One array will be logged to the console followed by an error message

['Denmark', 'Mexico', 'Morocco'];
TypeError: Assignment to constant variable