2. While Syntax


#1

I don't understand why, in the previous example, the lesson goes:

while(coinFace === 0)

and that works, yet when I get to the next lesson, it requires me to use only two equals signs. Why does 1. work but 2. doesn't?


1.

var understand = true;

while(understand == 1){
	console.log("I'm learning while loops!");
	understand = false;
}

2.

var understand = true;

while(understand === 1){
	console.log("I'm learning while loops!");
	understand = false;
}


#2

using three equal signs also compares data type. understand is a boolean value, 1 is integer, data types do not match, condition evaluates to false

with two equal signs, the condition is true, since 1 is considered true. Data type is not relevant when comparing with two equal signs

you could also do:

while (understand === true)

now the data types also match


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.