There is a syntax error saying "expected ' ; '" but i cant figure out where and what is wrong with these lines of code! Please answer ASAP!


var i = 0;
for (i < 2; i++) {
while (i = 0) {
console.log("I don't know a thing about coding!");
i = 2;
do {
confirm ("Do you take back the statement?");
}while (i = 0);


3 things,


this is not how you do a for loop:

this is how:


you do the comparator opertar so not one = but two ==:



same thing as second two ==:



can u explain to me all three?
1. ive already stated the variable "I" so its a global variable and can be stated anywhere.
2. what is the difference between i=0 and i==0???


Difference between "=" and "==":
"=" is a reference, actually "=" invoke builtin function id() which return internally memory address location for an object.
"==" is just arithmetic equal.


I thought === was equal


for (i < 2; i++) { do something}; --> you missed ;
for (; i < 2; i++) { do something}; --> correct


Actually is an comparison operators, sorry


k I understand now thx a lot man u rock!


== and === are both operators that check for the equality of 2 values the key difference is that === is more strict and not only checks for the values but also for the types e.g.

42 == "42" --> true, same value 42 
42 === "42" --> false, same value 42 different types number vs String

As @echosomething already mentioned you can leave out up to all 3 parts of the for loop (infinite loop) but you always have to have 2 semicolons in the () of the for loop to separate the 3 parts of it even if you don't directly state them. Last but not least loops do not require a semicolon at the end of their }.