15 computers are smart,


#1

Is there a bug here?

since the "if" condition is false, the "else" console.log is supposed to run RIGHT?

look at my results,


#2

Your condition is a string, it's text, a series of characters. It's not code, it doesn't do anything, doesn't compare anything.


#3

but as it stand it's false right, I would say equating/comparing 32 to 23.


#4

No its a string so its just reading it like a sentence you would need to have entered that statement without the " " and it would have return the 2nd console.log statement.

if ( 32 === 23) would make the 2nd console.log print


#5

Wow! interesting, thank you very much guys, but then what does this say about (conditions)? they have to be "doing, acting, comparing" in order for them to be true/false booleans.
In this case I messed up with "quotations", which becomes my coding problem. Thank you very much once again!


#6

That they don't strictly have to be boolean


#7

or they strictly have to be boolean, depending on the question? I have learnt something very valuable today. much appreciated again!


#8

The big thing to take with you is that "" create strings and that those are not code.

Sometimes it can make sense to use other values than true/false as a condition, but it's usually better to just say what the intention is, write them as comparisons anyway.

An example, not good code, more of how it can be used:

var i = 6;
while (--i) {
    console.log(i);
}

This is preferred, because everyone knows what it is almost without reading it. It's a common pattern.

for (var i = 0; i < 6; ++i) {
    console.log(i);
}

#9

Here is an explanation of truthy or falsey. There might be better explanations out there but this one came up first in a Google search.

tl:dr
All strings, except "" evaluate to true. That is what you are seeing there.