diff --git a/bubble-sort/index.js b/bubble-sort/index.js index 6d00634..a947070 100644 --- a/bubble-sort/index.js +++ b/bubble-sort/index.js @@ -98,7 +98,7 @@ function bubbleSort(arr) { * Our condition dictates that arr[i] must be greater than arr[i + 1] by employing the greater than operator. * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Greater_than_operator * - * As a reminder, arr is our single parameter being passed to our bubbleSort function. arr must be an Array. + * As a reminder, arr is the single parameter of our bubbleSort function and arr must be an Array. * See https://github.com/floatsoft/javascript-references/blob/bubble-sort/index.js#L13-L19 * * We can select elements from our array by referencing there index. @@ -114,7 +114,7 @@ function bubbleSort(arr) { * For more information on variable declarations see * https://github.com/floatsoft/javascript-references/blob/hello-world/varDeclaration.js#L9-L15 * - * We do this so that we do not loss the value of arr[i] during the swapping process. + * We do this so that we do not lose the value of arr[i] during the swapping process. * This is because we are doing our element swapping in-place. * See https://en.wikipedia.org/wiki/In-place_algorithm */ @@ -131,7 +131,7 @@ function bubbleSort(arr) { arr[i] = arr[i + 1]; /** - * We can now complete our swap by assigning arr[i + 1] to the value of temp which is equal to the previous value of arr[i]. + * We can now complete our swap by assigning arr[i + 1] to the value of tmp which is equal to the previous value of arr[i]. */ arr[i + 1] = tmp; @@ -139,7 +139,7 @@ function bubbleSort(arr) { * Our variable named swapped is now reassigned the boolean value of true. * This means that the condition of our do...while loop will be met. * Therefore our do...while loop will continue to execute until this block statement no longer executes, - * and subsequently our variable named swapped is never reassignment. + * and subsequently our variable named swapped is never reassigned. * In other words the condition of our if statement dictating that arr[i] must be greater than arr[i + 1] * must evaluate to a falsy value for each element pair in our array, arr, in order to exit from our do...while loop. */ @@ -153,7 +153,7 @@ function bubbleSort(arr) { } } /** - * The condition on this do...while loop is that is must run at least once and until swapped is false. + * The condition of our do...while loop is that it must run at least once and until swapped is false. * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/do...while#Syntax */ } while (swapped); 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 diff --git a/hello-world/index.js b/hello-world/index.js new file mode 100644 index 0000000..f93ad8a --- /dev/null +++ b/hello-world/index.js @@ -0,0 +1,22 @@ +/** + * 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. + */ + +/** + * 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/hello-world/varDeclaration.js b/hello-world/varDeclaration.js new file mode 100644 index 0000000..ee30c26 --- /dev/null +++ b/hello-world/varDeclaration.js @@ -0,0 +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"; + +/** + * 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/hello-world/varExport.js b/hello-world/varExport.js new file mode 100644 index 0000000..20de3d9 --- /dev/null +++ b/hello-world/varExport.js @@ -0,0 +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. + */ + +/** + * 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/hello-world/varImport.js b/hello-world/varImport.js new file mode 100644 index 0000000..f91e1f1 --- /dev/null +++ b/hello-world/varImport.js @@ -0,0 +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. + */ + +/** + * 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 + */