From 9c3c3dff4518671e82cd3324c0d6fdddd506dfd3 Mon Sep 17 00:00:00 2001 From: Leonardy Kristianto Date: Wed, 28 Oct 2015 02:04:34 +0800 Subject: [PATCH 01/14] Added resources to read for Javascript --- javascript.html.markdown | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/javascript.html.markdown b/javascript.html.markdown index cce488e1..dc573b0e 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -547,6 +547,11 @@ of the language. [JavaScript: The Definitive Guide][6] is a classic guide and reference book. +[Eloquent Javascript][8] by Marijn Haverbeke is an excellent JS book/ebook with attached terminal + +[Javascript: The Right Way][9] is a guide intended to introduce new developers to JavaScript and help experienced developers learn more about its best practices. + + In addition to direct contributors to this article, some content is adapted from Louie Dinh's Python tutorial on this site, and the [JS Tutorial][7] on the Mozilla Developer Network. @@ -559,3 +564,5 @@ Mozilla Developer Network. [5]: http://bonsaiden.github.io/JavaScript-Garden/ [6]: http://www.amazon.com/gp/product/0596805527/ [7]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript +[8]: http://eloquentjavascript.net/ +[9]: http://jstherightway.org/ From 3015cfb4367ffe7e06df5232cb4aa5924194715d Mon Sep 17 00:00:00 2001 From: Leonardy Kristianto Date: Wed, 28 Oct 2015 02:14:13 +0800 Subject: [PATCH 02/14] Rename go.html.markdown to go-hu.html.markdown --- hu-hu/{go.html.markdown => go-hu.html.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename hu-hu/{go.html.markdown => go-hu.html.markdown} (100%) diff --git a/hu-hu/go.html.markdown b/hu-hu/go-hu.html.markdown similarity index 100% rename from hu-hu/go.html.markdown rename to hu-hu/go-hu.html.markdown From f1d18e7e493c468f372598620837fedfb07271bf Mon Sep 17 00:00:00 2001 From: Leonardy Kristianto Date: Wed, 28 Oct 2015 02:14:30 +0800 Subject: [PATCH 03/14] Rename ruby.html.markdown to ruby-hu.html.markdown --- hu-hu/{ruby.html.markdown => ruby-hu.html.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename hu-hu/{ruby.html.markdown => ruby-hu.html.markdown} (100%) diff --git a/hu-hu/ruby.html.markdown b/hu-hu/ruby-hu.html.markdown similarity index 100% rename from hu-hu/ruby.html.markdown rename to hu-hu/ruby-hu.html.markdown From d684a44259348f52ed86d6e02b773f83b1547fad Mon Sep 17 00:00:00 2001 From: Leonardy Kristianto Date: Wed, 28 Oct 2015 02:15:29 +0800 Subject: [PATCH 04/14] Rename css.html.markdown to css-ta.html.markdown --- ta_in/{css.html.markdown => css-ta.html.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ta_in/{css.html.markdown => css-ta.html.markdown} (100%) diff --git a/ta_in/css.html.markdown b/ta_in/css-ta.html.markdown similarity index 100% rename from ta_in/css.html.markdown rename to ta_in/css-ta.html.markdown From 7d4522b5125da0a97ed0fe1f684cb50606e7b12d Mon Sep 17 00:00:00 2001 From: Leonardy Kristianto Date: Wed, 28 Oct 2015 02:15:46 +0800 Subject: [PATCH 05/14] Rename javascript.html.markdown to javascript-ta.html.markdown --- ta_in/{javascript.html.markdown => javascript-ta.html.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ta_in/{javascript.html.markdown => javascript-ta.html.markdown} (100%) diff --git a/ta_in/javascript.html.markdown b/ta_in/javascript-ta.html.markdown similarity index 100% rename from ta_in/javascript.html.markdown rename to ta_in/javascript-ta.html.markdown From 32d040d3b4c4f1e8b022e27614531a462c9bb344 Mon Sep 17 00:00:00 2001 From: Leonardy Kristianto Date: Wed, 28 Oct 2015 02:15:57 +0800 Subject: [PATCH 06/14] Rename json.html.markdown to json-ta.html.markdown --- ta_in/{json.html.markdown => json-ta.html.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ta_in/{json.html.markdown => json-ta.html.markdown} (100%) diff --git a/ta_in/json.html.markdown b/ta_in/json-ta.html.markdown similarity index 100% rename from ta_in/json.html.markdown rename to ta_in/json-ta.html.markdown From c677ba561290866ef791c2cb813afaf1aae09a32 Mon Sep 17 00:00:00 2001 From: Leonardy Kristianto Date: Wed, 28 Oct 2015 02:16:12 +0800 Subject: [PATCH 07/14] Rename xml.html.markdown to xml-ta.html.markdown --- ta_in/{xml.html.markdown => xml-ta.html.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ta_in/{xml.html.markdown => xml-ta.html.markdown} (100%) diff --git a/ta_in/xml.html.markdown b/ta_in/xml-ta.html.markdown similarity index 100% rename from ta_in/xml.html.markdown rename to ta_in/xml-ta.html.markdown From 897159a9392b3c9be6a548c9cd0d85b6c4e20f37 Mon Sep 17 00:00:00 2001 From: Leonardy Kristianto Date: Wed, 28 Oct 2015 02:16:49 +0800 Subject: [PATCH 08/14] Rename brainfuck.html.markdown to brainfuck-fa.html.markdown --- fa-ir/{brainfuck.html.markdown => brainfuck-fa.html.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename fa-ir/{brainfuck.html.markdown => brainfuck-fa.html.markdown} (100%) diff --git a/fa-ir/brainfuck.html.markdown b/fa-ir/brainfuck-fa.html.markdown similarity index 100% rename from fa-ir/brainfuck.html.markdown rename to fa-ir/brainfuck-fa.html.markdown From 5cbf6497b954ab97a89f207a4bdf69e77771c981 Mon Sep 17 00:00:00 2001 From: Leonardy Kristianto Date: Wed, 28 Oct 2015 02:17:06 +0800 Subject: [PATCH 09/14] Rename javascript.html.markdown to javascript-fa.html.markdown --- fa-ir/{javascript.html.markdown => javascript-fa.html.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename fa-ir/{javascript.html.markdown => javascript-fa.html.markdown} (100%) diff --git a/fa-ir/javascript.html.markdown b/fa-ir/javascript-fa.html.markdown similarity index 100% rename from fa-ir/javascript.html.markdown rename to fa-ir/javascript-fa.html.markdown From 61aa6a3e0146faed45230111b0bdcf1b0c2209f8 Mon Sep 17 00:00:00 2001 From: Corban Mailloux Date: Tue, 27 Oct 2015 22:18:02 -0400 Subject: [PATCH 10/14] "wan't" -> "want" --- javascript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript.html.markdown b/javascript.html.markdown index dc573b0e..b54434e0 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -145,7 +145,7 @@ someOtherVar = 10; // Variables declared without being assigned to are set to undefined. var someThirdVar; // = undefined -// if you wan't to declare a couple of variables, then you could use a comma +// if you want to declare a couple of variables, then you could use a comma // separator var someFourthVar = 2, someFifthVar = 4; From a8d5105fab5e40923d834fb5848aabf561bc1701 Mon Sep 17 00:00:00 2001 From: Corban Mailloux Date: Tue, 27 Oct 2015 22:47:03 -0400 Subject: [PATCH 11/14] [javascript/en] Spacing and capitalization of comments ... and a few grammar fixes. --- javascript.html.markdown | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/javascript.html.markdown b/javascript.html.markdown index b54434e0..5bac3aa7 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -136,7 +136,7 @@ undefined; // used to indicate a value is not currently present (although // character. var someVar = 5; -// if you leave the var keyword off, you won't get an error... +// If you leave the var keyword off, you won't get an error... someOtherVar = 10; // ...but your variable will be created in the global scope, not in the scope @@ -145,7 +145,7 @@ someOtherVar = 10; // Variables declared without being assigned to are set to undefined. var someThirdVar; // = undefined -// if you want to declare a couple of variables, then you could use a comma +// If you want to declare a couple of variables, then you could use a comma // separator var someFourthVar = 2, someFifthVar = 4; @@ -223,15 +223,15 @@ for (var i = 0; i < 5; i++){ // will run 5 times } -//The For/In statement loops iterates over every property across the entire prototype chain +// The for/in statement iterates over every property across the entire prototype chain. var description = ""; var person = {fname:"Paul", lname:"Ken", age:18}; for (var x in person){ description += person[x] + " "; } -//If only want to consider properties attached to the object itself, -//and not its prototypes use hasOwnProperty() check +// To only consider properties attached to the object itself +// and not its prototypes, use the `hasOwnProperty()` check. var description = ""; var person = {fname:"Paul", lname:"Ken", age:18}; for (var x in person){ @@ -240,8 +240,9 @@ for (var x in person){ } } -//for/in should not be used to iterate over an Array where the index order is important. -//There is no guarantee that for/in will return the indexes in any particular order +// For/in should not be used to iterate over an Array where the index order +// is important, as there is no guarantee that for/in will return the indexes +// in any particular order. // && is logical and, || is logical or if (house.size == "big" && house.colour == "blue"){ @@ -256,7 +257,7 @@ var name = otherName || "default"; // The `switch` statement checks for equality with `===`. -// use 'break' after each case +// Use 'break' after each case // or the cases after the correct one will be executed too. grade = 'B'; switch (grade) { From c83eb6c6bca63b28a11b975cc64db5723e94b240 Mon Sep 17 00:00:00 2001 From: Adam Brenecki Date: Wed, 28 Oct 2015 13:26:24 +1030 Subject: [PATCH 12/14] [javascript/en] Move comparisons to other languages into preamble --- javascript.html.markdown | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/javascript.html.markdown b/javascript.html.markdown index 5bac3aa7..3f9eb641 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -16,9 +16,14 @@ JavaScript isn't just limited to web browsers, though: Node.js, a project that provides a standalone runtime for Google Chrome's V8 JavaScript engine, is becoming more and more popular. +JavaScript has a C-like syntax, so if you've used languages like C or Java, +a lot of the basic syntax will already be familiar. Despite this, and despite +the similarity in name, JavaScript's object model is significantly different to +Java's. + ```js -// Comments are like C's. Single-line comments start with two slashes, -/* and multiline comments start with slash-star +// Single-line comments start with two slashes. +/* Multiline comments start with slash-star, and end with star-slash */ // Statements can be terminated by ; @@ -145,7 +150,7 @@ someOtherVar = 10; // Variables declared without being assigned to are set to undefined. var someThirdVar; // = undefined -// If you want to declare a couple of variables, then you could use a comma +// If you want to declare a couple of variables, then you could use a comma // separator var someFourthVar = 2, someFifthVar = 4; @@ -194,8 +199,6 @@ myObj.myFourthKey; // = undefined /////////////////////////////////// // 3. Logic and Control Structures -// The syntax for this section is almost identical to Java's. - // The `if` structure works as you'd expect. var count = 1; if (count == 3){ From d4d471ef50fb2e84dc8f1656a7037795bd44a89a Mon Sep 17 00:00:00 2001 From: Adam Brenecki Date: Wed, 28 Oct 2015 13:27:48 +1030 Subject: [PATCH 13/14] [javascript/en] Formatting fix --- javascript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript.html.markdown b/javascript.html.markdown index 3f9eb641..b5c3a3c8 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -41,7 +41,7 @@ doStuff() // JavaScript has one number type (which is a 64-bit IEEE 754 double). // Doubles have a 52-bit mantissa, which is enough to store integers -// up to about 9✕10¹⁵ precisely. +// up to about 9✕10¹⁵ precisely. 3; // = 3 1.5; // = 1.5 From c3a66e60a61de0b98ea3e86568dfddf76eae1069 Mon Sep 17 00:00:00 2001 From: Adam Brenecki Date: Wed, 28 Oct 2015 13:48:53 +1030 Subject: [PATCH 14/14] [javascript/en] Re-add note about truthiness of wrapped primitives Previous incarnations of this section had `Number(0)` instead of `new Number(0)`, which actually returns `0` due to the absence of the `new` keyword; this commit re-adds that section and better still, makes it actually correct! --- javascript.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/javascript.html.markdown b/javascript.html.markdown index b5c3a3c8..cd75b0d2 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -507,6 +507,10 @@ myNumber === myNumberObj; // = false if (0){ // This code won't execute, because 0 is falsy. } +if (new Number(0)){ + // This code will execute, because wrapped numbers are objects, and objects + // are always truthy. +} // However, the wrapper objects and the regular builtins share a prototype, so // you can actually add functionality to a string, for instance.