0

I have arrays in my code like this:

let shoppinglist = ['laptop','ram','screen'];

let anynum = [1,2,nan,true,null,'dog'];

let colour = ['red'];

let shoppingList2 = ['cheese','2 milk'];

let myapp = [0,1,2,3,4,5]; 

but I got this error when running:

Uncaught SyntaxError: Identifier 'colour' has already been declared
myapp
VM192:1 Uncaught ReferenceError: myapp is not defined
    at <anonymous>:1:1
(anonymous) @ VM192:1
shoppinglist.length
VM240:1 Uncaught ReferenceError: shoppinglist is not defined
    at <anonymous>:1:1
(anonymous) @ VM240:1
shoppingList2
VM264:1 Uncaught ReferenceError: shoppingList2 is not defined
    at <anonymous>:1:1
(anonymous) @ VM264:1   
4
  • 2
    Error is not related to code here. What's nan? Commented Jun 20, 2020 at 8:56
  • 4
    Show the code that throws these errors, the above code just consists of variable assignments. Also as @Kooilnc said, there's no such thing as nan , its NaN Commented Jun 20, 2020 at 8:58
  • You are showing us the variable declaration, but the problem you get is when you use them and this part of code is not provided. So first look at it and after that tell us what you have tried to solve . Commented Jun 20, 2020 at 9:25
  • Can you show all the javascript ? you are just showing the variables declaration Commented Jun 20, 2020 at 9:26

3 Answers 3

2

You most likely already declared the variable name 'colour' earlier in your code, so if you want to reassign it, use just:

colour = ['red'];

However, this will not work it you created the variable as 'const'. And nan should be NaN. In relation to the other errors, can you share the beginning of your code?

Sign up to request clarification or add additional context in comments.

1 Comment

yes thankyou..even after refreshing page my code started working
0

You have done a simple mistake there, nan is a keyword in javascript. You can make this as a string otherwise you can make it NaN.

  let shoppinglist = ['laptop','ram','screen'];

  let anynum = [1,2,NaN,true,null,'dog'];

  let colour = ['red'];

  let shoppingList2 = ['cheese','2 milk'];

  let myapp = [0,1,2,3,4,5];

1 Comment

yes thankyou..even after refreshing page my code started working
0

The value nan in the array anynum, is not just a value. nan is a keyword (built-in) put it as a string like let anynum = [1,2,'nan',true,null,'dog']; other than that array declaration is correct.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.