From eaa869809efb4002690861c6c9dca9edebba2fcb Mon Sep 17 00:00:00 2001 From: Kevin Gonzalez Date: Mon, 3 Jun 2019 12:27:57 +0200 Subject: [PATCH 1/5] Hello world examples with documentation for es5 and es6 with import and export --- README.md | 3 +++ index.js | 18 ++++++++++++++++++ varDeclaration.js | 31 +++++++++++++++++++++++++++++++ varExport.js | 30 ++++++++++++++++++++++++++++++ varImport.js | 24 ++++++++++++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 index.js create mode 100644 varDeclaration.js create mode 100644 varExport.js create mode 100644 varImport.js diff --git a/README.md b/README.md index 1b3a383..a58979d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # javascript-references Material to reference when working with JavaScript + +# Hello World +This reference explains how to print "Hello World" to the console with JavaScript. \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..91a54b5 --- /dev/null +++ b/index.js @@ -0,0 +1,18 @@ +/** No need to "use strict" + In this case even though we are not declaring this code as an ES6 module + the following code contains no syntax that can be caught by strict mode. + See ./varDeclaration.js for an example that can benefit from strict mode. +*/ + +/** The Console object provides access to the browser's debugging console + See https://developer.mozilla.org/en-US/docs/Web/API/console + The Console object's methods include log() + The Console method log() outputs a message to the console. + The message is not limited to a single string. + See https://developer.mozilla.org/en-US/docs/Web/API/Console/log +*/ +console.log("Hello World"); + +/** The easiest way to test this file is to run the following line in your console: + node index.js +*/ diff --git a/varDeclaration.js b/varDeclaration.js new file mode 100644 index 0000000..54cf582 --- /dev/null +++ b/varDeclaration.js @@ -0,0 +1,31 @@ +/** "use strict" in this case + We are not declaring this code as an ES6 module and the following code + contains syntax that can be caught by strict mode. + See ./index.js for an example that does not benefit from strict mode. +*/ +"use strict"; + +/** The code below will declare a global string named helloWorld, + this is valid ES5 code, in ES6 we can also use let or const. + Normally in ES6 this would be declared as a const. + See ./es6.js for an example using const. +*/ +var helloWorld = "Hello World"; + +/** Strict mode will catch an undeclared variable i.e: + helloWorld = "Hello World" + The above commented line will throw an error in strict mode. +*/ + +/** The Console object provides access to the browser's debugging console + See https://developer.mozilla.org/en-US/docs/Web/API/console + The Console object's methods include log() + The Console method log() outputs a message to the console. + The message is not limited to a single string. + See https://developer.mozilla.org/en-US/docs/Web/API/Console/log +*/ +console.log(helloWorld); + +/** The easiest way to test this file is to run the following line in your console + node varDeclaration.js +*/ diff --git a/varExport.js b/varExport.js new file mode 100644 index 0000000..a80c2d7 --- /dev/null +++ b/varExport.js @@ -0,0 +1,30 @@ +/** Do not include "use strict" + In this case we are declaring this code as an ES6 module, + module code is always strict mode code. + See http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-code + See ./varDeclaration.js for an example that is not in strict mode by default. +*/ + +/** The code below will declare and export a string constant named helloWorld, + this is valid ES6 code, in ES5 we can only use var. + See ./varDeclaration.js for an example using var. +*/ +export const helloWorld = "Hello World"; + +/** Strict mode will catch an undeclared variable i.e: + helloWorld = "Hello World" + The above commented line will throw an error in strict mode. +*/ + +/** The Console object provides access to the browser's debugging console + See https://developer.mozilla.org/en-US/docs/Web/API/console + The Console object's methods include log() + The Console method log() outputs a message to the console. + The message is not limited to a single string. + See https://developer.mozilla.org/en-US/docs/Web/API/Console/log +*/ +console.log(helloWorld); + +/** The easiest way to test this file is to run the following line in your console + nodemon varDeclaration.js +*/ diff --git a/varImport.js b/varImport.js new file mode 100644 index 0000000..fb548e6 --- /dev/null +++ b/varImport.js @@ -0,0 +1,24 @@ +/** Do not include "use strict" + In this case we are declaring this code as an ES6 module, + module code is always strict mode code. + See http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-code + See ./varDeclaration.js for an example that is not in strict mode by default. +*/ + +/** The code below will declare and import a string constant named helloWorld. + See ./varExport.js +*/ +import { helloWorld } from "./varExport"; + +/** The Console object provides access to the browser's debugging console + See https://developer.mozilla.org/en-US/docs/Web/API/console + The Console object's methods include log() + The Console method log() outputs a message to the console. + The message is not limited to a single string. + See https://developer.mozilla.org/en-US/docs/Web/API/Console/log +*/ +console.log(helloWorld); + +/** The easiest way to test this file is to run the following line in your console + nodemon varDeclaration.js +*/ From b8ec4650c21f42adeef2471d0104c782f315e651 Mon Sep 17 00:00:00 2001 From: Kevin Gonzalez Date: Wed, 5 Jun 2019 14:15:29 +0200 Subject: [PATCH 2/5] Prettier comments --- index.js | 33 +++++++++++++++-------------- varDeclaration.js | 53 ++++++++++++++++++++++++++--------------------- varExport.js | 53 ++++++++++++++++++++++++++--------------------- varImport.js | 42 ++++++++++++++++++++----------------- 4 files changed, 99 insertions(+), 82 deletions(-) diff --git a/index.js b/index.js index 91a54b5..d39eb24 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,21 @@ -/** No need to "use strict" - In this case even though we are not declaring this code as an ES6 module - the following code contains no syntax that can be caught by strict mode. - See ./varDeclaration.js for an example that can benefit from strict mode. -*/ +/** + * No need to "use strict" + * In this case even though we are not declaring this code as an ES6 module + * the following code contains no syntax that can be caught by strict mode. + * See ./varDeclaration.js for an example that can benefit from strict mode. + */ -/** The Console object provides access to the browser's debugging console - See https://developer.mozilla.org/en-US/docs/Web/API/console - The Console object's methods include log() - The Console method log() outputs a message to the console. - The message is not limited to a single string. - See https://developer.mozilla.org/en-US/docs/Web/API/Console/log -*/ +/** + * The Console object provides access to the browser's debugging console + * See https://developer.mozilla.org/en-US/docs/Web/API/console + * The Console object's methods include log() + * The Console method log() outputs a message to the console. + * The message is not limited to a single string. + * See https://developer.mozilla.org/en-US/docs/Web/API/Console/log + */ console.log("Hello World"); -/** The easiest way to test this file is to run the following line in your console: - node index.js -*/ +/** + * The easiest way to test this file is to run the following line in your console: + * node index.js + */ diff --git a/varDeclaration.js b/varDeclaration.js index 54cf582..ee30c26 100644 --- a/varDeclaration.js +++ b/varDeclaration.js @@ -1,31 +1,36 @@ -/** "use strict" in this case - We are not declaring this code as an ES6 module and the following code - contains syntax that can be caught by strict mode. - See ./index.js for an example that does not benefit from strict mode. -*/ +/** + * "use strict" in this case + * We are not declaring this code as an ES6 module and the following code + * contains syntax that can be caught by strict mode. + * See ./index.js for an example that does not benefit from strict mode. + */ "use strict"; -/** The code below will declare a global string named helloWorld, - this is valid ES5 code, in ES6 we can also use let or const. - Normally in ES6 this would be declared as a const. - See ./es6.js for an example using const. -*/ +/** + * The code below will declare a global string named helloWorld, + * this is valid ES5 code, in ES6 we can also use let or const. + * Normally in ES6 this would be declared as a const. + * See ./es6.js for an example using const. + */ var helloWorld = "Hello World"; -/** Strict mode will catch an undeclared variable i.e: - helloWorld = "Hello World" - The above commented line will throw an error in strict mode. -*/ +/** + * Strict mode will catch an undeclared variable i.e: + * helloWorld = "Hello World" + * The above commented line will throw an error in strict mode. + */ -/** The Console object provides access to the browser's debugging console - See https://developer.mozilla.org/en-US/docs/Web/API/console - The Console object's methods include log() - The Console method log() outputs a message to the console. - The message is not limited to a single string. - See https://developer.mozilla.org/en-US/docs/Web/API/Console/log -*/ +/** + * The Console object provides access to the browser's debugging console + * See https://developer.mozilla.org/en-US/docs/Web/API/console + * The Console object's methods include log() + * The Console method log() outputs a message to the console. + * The message is not limited to a single string. + * See https://developer.mozilla.org/en-US/docs/Web/API/Console/log + */ console.log(helloWorld); -/** The easiest way to test this file is to run the following line in your console - node varDeclaration.js -*/ +/** + * The easiest way to test this file is to run the following line in your console: + * node varDeclaration.js + */ diff --git a/varExport.js b/varExport.js index a80c2d7..20de3d9 100644 --- a/varExport.js +++ b/varExport.js @@ -1,30 +1,35 @@ -/** Do not include "use strict" - In this case we are declaring this code as an ES6 module, - module code is always strict mode code. - See http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-code - See ./varDeclaration.js for an example that is not in strict mode by default. -*/ +/** + * Do not include "use strict" + * In this case we are declaring this code as an ES6 module, + * module code is always strict mode code. + * See http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-code + * See ./varDeclaration.js for an example that is not in strict mode by default. + */ -/** The code below will declare and export a string constant named helloWorld, - this is valid ES6 code, in ES5 we can only use var. - See ./varDeclaration.js for an example using var. -*/ +/** + * The code below will declare and export a string constant named helloWorld, + * this is valid ES6 code, in ES5 we can only use var. + * See ./varDeclaration.js for an example using var. + */ export const helloWorld = "Hello World"; -/** Strict mode will catch an undeclared variable i.e: - helloWorld = "Hello World" - The above commented line will throw an error in strict mode. -*/ +/** + * Strict mode will catch an undeclared variable i.e: + * helloWorld = "Hello World" + * The above commented line will throw an error in strict mode. + */ -/** The Console object provides access to the browser's debugging console - See https://developer.mozilla.org/en-US/docs/Web/API/console - The Console object's methods include log() - The Console method log() outputs a message to the console. - The message is not limited to a single string. - See https://developer.mozilla.org/en-US/docs/Web/API/Console/log -*/ +/** + * The Console object provides access to the browser's debugging console + * See https://developer.mozilla.org/en-US/docs/Web/API/console + * The Console object's methods include log() + * The Console method log() outputs a message to the console. + * The message is not limited to a single string. + * See https://developer.mozilla.org/en-US/docs/Web/API/Console/log + */ console.log(helloWorld); -/** The easiest way to test this file is to run the following line in your console - nodemon varDeclaration.js -*/ +/** + * The easiest way to test this file is to run the following line in your console + * nodemon varDeclaration.js + */ diff --git a/varImport.js b/varImport.js index fb548e6..f91e1f1 100644 --- a/varImport.js +++ b/varImport.js @@ -1,24 +1,28 @@ -/** Do not include "use strict" - In this case we are declaring this code as an ES6 module, - module code is always strict mode code. - See http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-code - See ./varDeclaration.js for an example that is not in strict mode by default. -*/ +/** + * Do not include "use strict" + * In this case we are declaring this code as an ES6 module, + * module code is always strict mode code. + * See http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-code + * See ./varDeclaration.js for an example that is not in strict mode by default. + */ -/** The code below will declare and import a string constant named helloWorld. - See ./varExport.js -*/ +/** + * The code below will declare and import a string constant named helloWorld. + * See ./varExport.js + */ import { helloWorld } from "./varExport"; -/** The Console object provides access to the browser's debugging console - See https://developer.mozilla.org/en-US/docs/Web/API/console - The Console object's methods include log() - The Console method log() outputs a message to the console. - The message is not limited to a single string. - See https://developer.mozilla.org/en-US/docs/Web/API/Console/log -*/ +/** + * The Console object provides access to the browser's debugging console + * See https://developer.mozilla.org/en-US/docs/Web/API/console + * The Console object's methods include log() + * The Console method log() outputs a message to the console. + * The message is not limited to a single string. + * See https://developer.mozilla.org/en-US/docs/Web/API/Console/log + */ console.log(helloWorld); -/** The easiest way to test this file is to run the following line in your console - nodemon varDeclaration.js -*/ +/** + * The easiest way to test this file is to run the following line in your console: + * nodemon varDeclaration.js + */ From a8a21cf1f9866c2693721c181b4ab6dae4af4dd8 Mon Sep 17 00:00:00 2001 From: Kevin Gonzalez <19812642+typekev@users.noreply.github.com> Date: Wed, 5 Jun 2019 15:44:45 +0200 Subject: [PATCH 3/5] Link to detailed "strict mode" documentation --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index d39eb24..f93ad8a 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ * No need to "use strict" * In this case even though we are not declaring this code as an ES6 module * the following code contains no syntax that can be caught by strict mode. + * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode * See ./varDeclaration.js for an example that can benefit from strict mode. */ From 22d25537fb2cd9465952986f66c13c5b9e023a45 Mon Sep 17 00:00:00 2001 From: Kevin Gonzalez Date: Fri, 7 Jun 2019 15:12:39 +0200 Subject: [PATCH 4/5] Move hello world references into hello-world dir in prep for merg --- index.js => hello-world/index.js | 0 varDeclaration.js => hello-world/varDeclaration.js | 0 varExport.js => hello-world/varExport.js | 0 varImport.js => hello-world/varImport.js | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename index.js => hello-world/index.js (100%) rename varDeclaration.js => hello-world/varDeclaration.js (100%) rename varExport.js => hello-world/varExport.js (100%) rename varImport.js => hello-world/varImport.js (100%) diff --git a/index.js b/hello-world/index.js similarity index 100% rename from index.js rename to hello-world/index.js diff --git a/varDeclaration.js b/hello-world/varDeclaration.js similarity index 100% rename from varDeclaration.js rename to hello-world/varDeclaration.js diff --git a/varExport.js b/hello-world/varExport.js similarity index 100% rename from varExport.js rename to hello-world/varExport.js diff --git a/varImport.js b/hello-world/varImport.js similarity index 100% rename from varImport.js rename to hello-world/varImport.js From a579becacd233dd12d1cbee71e98acff30cdba5b Mon Sep 17 00:00:00 2001 From: Kevin Gonzalez Date: Tue, 11 Jun 2019 16:57:32 +0200 Subject: [PATCH 5/5] Added Hello World description in ReadMe, in hello-world dir --- README.md | 4 +--- hello-world/README.md | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 hello-world/README.md diff --git a/README.md b/README.md index a58979d..bcc622f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ # javascript-references -Material to reference when working with JavaScript -# Hello World -This reference explains how to print "Hello World" to the console with JavaScript. \ No newline at end of file +Material to reference when working with JavaScript diff --git a/hello-world/README.md b/hello-world/README.md new file mode 100644 index 0000000..962c72f --- /dev/null +++ b/hello-world/README.md @@ -0,0 +1,3 @@ +# Hello World in JavaScript + +A set of scripts that output the message "Hello World". Such a program is very simple in most programming languages, and is often used to illustrate the basic syntax of a programming language. See https://en.wikipedia.org/wiki/%22Hello,_World!%22_program