Results 1 to 11 of 11
-
December 14th, 2011, 02:22 AM #1
Tutorial: If and Else Statements in JS
Hi everyone,
This is the happening place to discuss all things related to the If and Else Statements in JS tutorial.
Cheers,
Kirupa
-
December 14th, 2011, 05:08 AM #2
Please add some notes on triple equal '==='.

I want triple equals
Originally Posted by Crockford
.
Does ternary operator includes here? Or that can be another tutorial on conditionals.
-
December 14th, 2011, 05:20 AM #3
Here's another case where I disagree with Crockford. I know exactly how == and === differ, have known for years, and still find that == is almost always what I want and intend. However, I wouldn't try to convince people to use one over the other like he has (in my opinion, unfortunately) done.
-
December 14th, 2011, 10:44 PM #4
So you are saying that there is no point in all the javascript conventions written by Crockford? And Ecma-262 5.1 Edition is the holy grail of JavaScript and there is no point in JavaScript The Good Parts by Crockford?
-
December 15th, 2011, 03:16 AM #5
Nope, I'm just disagreeing with this one piece of his advice. (I said 'another' because there was another of his pieces of advice mentioned recently in a different thread.) I'm not saying anything as sensational as you're implying.
-
December 15th, 2011, 03:09 PM #6
Maybe it's good to point out that there are ways to write 'if' and 'if/else' statements using shorter syntax.
Not that I recommend to use them, as they are hard to read, but it's a good thing to know what these statements do...
A few examples:
Short IF
Short IFCode:if (variable_1 == 80) alert("something");
Short ORCode:(variable_1 == 80) && alert("something");
Short if/elseCode:variable_1 = some_property || 0;
Short if/elseCode:alert( (variable_1==80) ? 'eighty' : 'not eighty' );
Code:variable_1 = some_property ? 1 : 0;
-
December 15th, 2011, 06:37 PM #7
-
December 15th, 2011, 09:53 PM #8
-
December 16th, 2011, 06:35 AM #9
I think it would make sense to say in this tutorial that the condition for an if statement doesn't necessarily need to be a comparison between two operands. It can be any expression that evaluates to a boolean. It would then probably make sense to say what different literal values and complex objects resolve to when coerced.
I just read some stuff by him and I disagree with a lot of it, mostly because I think a lot of it has no reason and is just an attempt to create an arbitrary convention. Not that following a standard is bad per se, he just makes it seem like what he's saying is absolute truth. But I may be misinterpreting the tone of the article.Proud Montanadian
We tolerate living and breathing. And niches.
Name Brand Watches
Maybe getTimer() or TweenMax is the answer to your problem . . .
-
December 16th, 2011, 07:11 AM #10It can be any expression. And any expression can be evaluated and converted to be a boolean value. (This might have been exactly what you were saying in your post, but the way that I read your post seemed to imply that there are some expressions that you couldn't use in an if statement.)
Originally Posted by TheCanadian
I agree that the additional explanation that you suggested for the tutorial would be useful.
I interpret his tone in the same way!
Originally Posted by TheCanadian
-
December 16th, 2011, 07:45 AM #11

Reply With Quote


Bookmarks