From fb28f2c10258eb92dc40db648a304f3e5b78bd2f Mon Sep 17 00:00:00 2001 From: ml242 Date: Mon, 27 Oct 2014 00:43:20 -0400 Subject: 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. --- javascript.html.markdown | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'javascript.html.markdown') 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' -- cgit v1.2.3 From eb43eb7ccdeaad7440d9fda90128691effda15e1 Mon Sep 17 00:00:00 2001 From: i Date: Tue, 28 Oct 2014 03:11:59 -0400 Subject: basic arithmetic *doesn't* work It's not really true that arithmetic is accurate in JavaScript. --- javascript.html.markdown | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index cc210c4a..792cab98 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -39,13 +39,14 @@ doStuff() // 1. Numbers, Strings and Operators // JavaScript has one number type (which is a 64-bit IEEE 754 double). -// As with Lua, don't freak out about the lack of ints: doubles have a 52-bit -// mantissa, which is enough to store integers up to about 9✕10¹⁵ precisely. +// Doubles have a 52-bit mantissa, which is enough to store integers +// up to about 9✕10¹⁵ precisely. 3; // = 3 1.5; // = 1.5 -// All the basic arithmetic works as you'd expect. +// Some basic arithmetic works as you'd expect. 1 + 1; // = 2 +.1 + .2; // = 0.30000000000000004 8 - 1; // = 7 10 * 2; // = 20 35 / 5; // = 7 -- cgit v1.2.3 From 9324987c1fc465379060491d9a4b1c25cffde0fc Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Thu, 30 Oct 2014 16:43:49 +0100 Subject: use propernotation for decimals --- javascript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'javascript.html.markdown') diff --git a/javascript.html.markdown b/javascript.html.markdown index 792cab98..a92dcb4a 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -46,7 +46,7 @@ doStuff() // Some basic arithmetic works as you'd expect. 1 + 1; // = 2 -.1 + .2; // = 0.30000000000000004 +0.1 + 0.2; // = 0.30000000000000004 8 - 1; // = 7 10 * 2; // = 20 35 / 5; // = 7 -- cgit v1.2.3