From 19a377def003d9992f631ff0727add5263eee824 Mon Sep 17 00:00:00 2001 From: Chris Zimmerman Date: Mon, 30 Sep 2019 17:55:50 -0400 Subject: Adds documentation for some basic ES6 features. --- javascript.html.markdown | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'javascript.html.markdown') 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 -- cgit v1.2.3 From eb6aa85639898f1c5a2f56718941454e8d993b98 Mon Sep 17 00:00:00 2001 From: Samuel Rabinowitz <5happy1@users.noreply.github.com> Date: Sat, 28 Dec 2019 16:50:01 -0700 Subject: Add missing semicolon for consistency --- 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 ce9772ca..ad1af76a 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -188,7 +188,7 @@ someVar = myArray.pop(); // Remove last element and return it // Join all elements of an array with semicolon var myArray0 = [32,false,"js",12,56,90]; -myArray0.join(";") // = "32;false;js;12;56;90" +myArray0.join(";"); // = "32;false;js;12;56;90" // Get subarray of elements from index 1 (include) to 4 (exclude) myArray0.slice(1,4); // = [false,"js",12] -- cgit v1.2.3 From 5864aba42d2cf57dfe96049568b3a9689ea6a813 Mon Sep 17 00:00:00 2001 From: Leigh Brenecki Date: Thu, 13 Feb 2020 10:38:29 +1030 Subject: Purge my deadname --- 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 ad1af76a..3c0e6d4f 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -1,7 +1,7 @@ --- language: javascript contributors: - - ["Adam Brenecki", "http://adam.brenecki.id.au"] + - ["Leigh Brenecki", "https://leigh.net.au"] - ["Ariel Krakowski", "http://www.learneroo.com"] filename: javascript.js --- -- cgit v1.2.3