summaryrefslogtreecommitdiffhomepage
path: root/javascript.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'javascript.html.markdown')
-rw-r--r--javascript.html.markdown21
1 files changed, 15 insertions, 6 deletions
diff --git a/javascript.html.markdown b/javascript.html.markdown
index 6ea0b0bb..d408e885 100644
--- a/javascript.html.markdown
+++ b/javascript.html.markdown
@@ -54,6 +54,11 @@ doStuff()
// Including uneven division.
5 / 2; // = 2.5
+// And modulo division.
+10 % 2; // = 0
+30 % 4; // = 2
+18.5 % 7; // = 4.5
+
// Bitwise operations also work; when you perform a bitwise operation your float
// is converted to a signed int *up to* 32 bits.
1 << 2; // = 4
@@ -104,7 +109,7 @@ null == undefined; // = true
// ...unless you use ===
"5" === 5; // = false
-null === undefined; // = false
+null === undefined; // = false
// ...which can result in some weird behaviour...
13 + !0; // 14
@@ -144,6 +149,10 @@ 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
+// separator
+var someFourthVar = 2, someFifthVar = 4;
+
// There's shorthand for performing math operations on variables:
someVar += 5; // equivalent to someVar = someVar + 5; someVar is 10 now
someVar *= 10; // now someVar is 100
@@ -220,15 +229,15 @@ for (var i = 0; i < 5; i++){
//The For/In statement loops iterates over every property across the entire prototype chain
var description = "";
-var person = {fname:"Paul", lname:"Ken", age:18};
+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,
+//If only want to consider properties attached to the object itself,
//and not its prototypes use hasOwnProperty() check
var description = "";
-var person = {fname:"Paul", lname:"Ken", age:18};
+var person = {fname:"Paul", lname:"Ken", age:18};
for (var x in person){
if (person.hasOwnProperty(x)){
description += person[x] + " ";
@@ -319,7 +328,7 @@ i; // = 5 - not undefined as you'd expect in a block-scoped language
// scope.
(function(){
var temporary = 5;
- // We can access the global scope by assiging to the "global object", which
+ // We can access the global scope by assigning to the "global object", which
// in a web browser is always `window`. The global object may have a
// different name in non-browser environments such as Node.js.
window.permanent = 10;
@@ -413,7 +422,7 @@ var doubler = product.bind(this, 2);
doubler(8); // = 16
// When you call a function with the `new` keyword, a new object is created, and
-// made available to the function via the this keyword. Functions designed to be
+// made available to the function via the `this` keyword. Functions designed to be
// called like that are called constructors.
var MyConstructor = function(){