Basically, we have two things: a console statement and then we have an array of numbers, but JavaScript doesn't treat this as an array of numbers. It is treated as that square bracket syntax. We use it to access a property on an array or object. [20,35,25,86] The separated values in those square brackets are just treated like comma-separated values, and when JavaScript sees comma-separated values, it evaluates each of the values and then just returns the last one, which is going to be 86, so this kind of simplifies to 86. JavaScript will also run the console.log function and use the return value of this function(console.log), which happens to be undefined. undefined[86] We're trying to access 86 on undefined, so if we run this code, we should get cannot read property of undefined, reading 86. So the solution here is to put the semicolon at the beginning of the line, and the reason is. It goes at the beginning of the line because it could really go at the end of the line, and even it could go in the middle, whatever, but the reason it should go at the beginning is to show anyone who is reading the code that you intended to put the semicolon there. If I put a semicolon at the end of a line, it kind of looks like I'm being inconsistent. I like to start using semicolons, but then just forgot for the rest of my code, but if I put the beginning.
Another common time when you will need a semicolon is when you're using an immediately invoked function expression. Console.log("hello") (()=>{ Console.log("hello") })() JavaScript is trying to run this all as one line, and none of the stuff is not matters; this is the only important part here. console.log("hello")() What's happening here is similar to what happened above. CLG function is evaluated, and we end up getting the return value of the CL,G which is undefined, and then it's trying to run undefined as a function which is going to give us Undefined() In React, if you're using an immediately invoked function expression within useEffect, then you must put a semicolon before the function, else it will throw an error.