summaryrefslogtreecommitdiffhomepage
path: root/javascript.html.markdown
diff options
context:
space:
mode:
authorDivay Prakash <divayprakash@users.noreply.github.com>2019-11-24 12:38:47 +0530
committerGitHub <noreply@github.com>2019-11-24 12:38:47 +0530
commitede3cc5484efe1966c0988a5b5fe6b7514205ce9 (patch)
tree10616a60734a9a896bfbbcca9578c36e390a1082 /javascript.html.markdown
parent3d75c100b4b79d78786860effb9dbaea1620e4ce (diff)
parentf0ce8b2ba2156c8f7e10f114245cc92f757fb6d1 (diff)
Merge branch 'master' into patch-4
Diffstat (limited to 'javascript.html.markdown')
-rw-r--r--javascript.html.markdown42
1 files changed, 42 insertions, 0 deletions
diff --git a/javascript.html.markdown b/javascript.html.markdown
index c466c09b..ce9772ca 100644
--- a/javascript.html.markdown
+++ b/javascript.html.markdown
@@ -586,6 +586,48 @@ if (Object.create === undefined){ // don't overwrite it if it exists
return new Constructor();
};
}
+
+// ES6 Additions
+
+// The "let" keyword allows you to define variables in a lexical scope,
+// as opposed to a block scope like the var keyword does.
+let name = "Billy";
+
+// Variables defined with let can be reassigned new values.
+name = "William";
+
+// The "const" keyword allows you to define a variable in a lexical scope
+// like with let, but you cannot reassign the value once one has been assigned.
+
+const pi = 3.14;
+
+pi = 4.13; // You cannot do this.
+
+// There is a new syntax for functions in ES6 known as "lambda syntax".
+// This allows functions to be defined in a lexical scope like with variables
+// defined by const and let.
+
+const isEven = (number) => {
+ return number % 2 === 0;
+};
+
+isEven(7); // false
+
+// The "equivalent" of this function in the traditional syntax would look like this:
+
+function isEven(number) {
+ return number % 2 === 0;
+};
+
+// I put the word "equivalent" in double quotes because a function defined
+// using the lambda syntax cannnot be called before the definition.
+// The following is an example of invalid usage:
+
+add(1, 8);
+
+const add = (firstNumber, secondNumber) => {
+ return firstNumber + secondNumber;
+};
```
## Further Reading