summaryrefslogtreecommitdiffhomepage
path: root/javascript.html.markdown
diff options
context:
space:
mode:
authorml242 <mattlucas@gmail.com>2014-10-27 00:43:20 -0400
committerml242 <mattlucas@gmail.com>2014-10-27 00:43:20 -0400
commitfb28f2c10258eb92dc40db648a304f3e5b78bd2f (patch)
tree2e89258ef20441ccc888ae76909ec71b303188b3 /javascript.html.markdown
parent4095671c9250aab8e15473bc73b5db2cdbc95229 (diff)
Your Name: Matt
Subject Line: Addresses Comparisons in Javascript What Happened: I believe that starting out with the double equals instead of the triple equals for strict comparison checking is incorrect. Because double equals uses type coercion, it is more of a feature the needs to be understood. Beginners looking at the language should look upon the stricter method as the proper one because it is less likely to give a surprising result. I also tried to address the behaviour by adding an example to the double equals comparison. Hope that the community is interested in pulling in these changes, they stem from teaching beginners javaScript but I am by no means the authority.
Diffstat (limited to 'javascript.html.markdown')
-rw-r--r--javascript.html.markdown16
1 files changed, 9 insertions, 7 deletions
diff --git a/javascript.html.markdown b/javascript.html.markdown
index 76017c17..f190ff98 100644
--- a/javascript.html.markdown
+++ b/javascript.html.markdown
@@ -77,13 +77,13 @@ false;
!true; // = false
!false; // = true
-// Equality is ==
-1 == 1; // = true
-2 == 1; // = false
+// Equality is ===
+1 === 1; // = true
+2 === 1; // = false
-// Inequality is !=
-1 != 1; // = false
-2 != 1; // = true
+// Inequality is !==
+1 !== 1; // = false
+2 !== 1; // = true
// More comparisons
1 < 10; // = true
@@ -97,11 +97,13 @@ false;
// and are compared with < and >
"a" < "b"; // = true
-// Type coercion is performed for comparisons...
+// Type coercion is performed for comparisons with double equals...
"5" == 5; // = true
+null == undefined; // = true
// ...unless you use ===
"5" === 5; // = false
+null === undefined; // = false
// You can access characters in a string with charAt
"This is a string".charAt(0); // = 'T'