Hey everyone, I have a question that's been bothering me and I can't seem to find the answer anywhere.
I'm currently learning pure JavaScript and although I am familiar with several other programming languages, I keep running into an issue with array assignment in JS.
var gear = []; // global assignment
gear[0]=200; // this line is causing an error
function bla(){
gear[0] = 200;// even putting it in a function doesn't work
}
// I keep getting an unexpected token "[" error. It's frustrating because even BASIC allows this.
After some research, I realized that my placement of the assignment may be incorrect. I've tried assigning globally and inside a function, but I still encounter errors.
So here are my questions regarding pure JS: Is it not possible to assign a numerical value to an array? Where should I place this assignment? If I'm doing this wrong (which seems likely), how can I make index 0 equal to a specific value? Do I need to use parentheses? My program was functioning perfectly until I tried adding arrays, now I'm stuck on this token error. (I could easily do this with console API, but I prefer a web-based solution)
Thank you all for your help!