Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion JavaScript_Advance/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ transformNumber(10, (num) => {
* passed to the `resolve()` function, will get passed to the function passed to `.then()`
* function. Look at the following example from MDN official documents:
*/
var p1 = new Promise((resolve, reject) => {
const p1 = new Promise((resolve, reject) => {
resolve("Success!");
// or
// reject(new Error("Error!"));
Expand Down
2 changes: 1 addition & 1 deletion JavaScript_Advance/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ console.log("Simple usage:" + document.cookie);
// #2 Get a cookie with the name 'actor'
document.cookie = "movie=Jungle Book";
document.cookie = "actor=Balu";
var cookieValue = document.cookie.replace(/(?:(?:^|.*;\s*)actor\s*\=\s*([^;]*).*$)|^.*$/, "$1");
const cookieValue = document.cookie.replace(/(?:(?:^|.*;\s*)actor\s*\=\s*([^;]*).*$)|^.*$/, "$1");
console.log("Cookie with the name 'actor':" + cookieValue);

// #3 Set cookie and execute code only once if cookie doesn't exist yet
Expand Down
2 changes: 1 addition & 1 deletion JavaScript_Advance/do_while_loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ do {

*/

var n = 1;
let n = 1;

do {
console.log("n is less than 6. n = " + n);
Expand Down
2 changes: 1 addition & 1 deletion JavaScript_Advance/while_loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

*/

var n = 1;
let n = 1;

while (n < 6) {
console.log("n is less than 6. n = " + n);
Expand Down
10 changes: 5 additions & 5 deletions JavaScript_Basics/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ console.log(easyMethod);
// Output [ 'Swapnil Satish Shinde', 76, true ]

// The pop() method removes the last element from an array:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.pop(); // Removes the last element ("Mango") from fruits and output is ["Banana","Orange","Apple"]

// Shifting is equivalent to popping, working on the first element instead of the last.
// The shift() method removes the first array element and "shifts" all other elements to a lower index.
var cars = ["Acura", "Audi", "Bugatti", "Honda"];
const cars = ["Acura", "Audi", "Bugatti", "Honda"];
cars.shift(); // Removes the first element ("Acura") from cars and output is ["Audi","Bugatti","Honda"]

// The length property provides an easy way to append a new element to an array:
var mobiles = ["Apple", "Nokia", "Samsung", "Sony"];
const mobiles = ["Apple", "Nokia", "Samsung", "Sony"];
mobiles[mobiles.length] = "HTC"; // Appends "HTC" to mobiles and output is ["Apple", "Nokia", "Samsung", "Sony", "HTC"]

// delete will delete the object property, but will not reindex the array or update its length. This makes it appears as if it is undefined:
var myArray = ["a", "b", "c", "d"];
const myArray = ["a", "b", "c", "d"];
delete myArray[0];
"The first value is: " + myArray[0]; // The first value is: undefined
// Using delete may leave undefined holes in the array. Use pop() or shift() instead.

// The splice() method removes items from array and/or adds items to array and returns the removed items:
var names = ["Anne", "Belle", "Chloe", "Diane", "Ella", "Frances"];
const names = ["Anne", "Belle", "Chloe", "Diane", "Ella", "Frances"];
names.splice(4, 1);
// This removes 1 item from index 4
// returns "Ella"
Expand Down
4 changes: 2 additions & 2 deletions JavaScript_Basics/bugs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var obj = {
const obj = {
name: "Some name"
};

var name = null;
const name = null;

console.log(typeof obj); // object;
console.log(typeof name); // object;
2 changes: 1 addition & 1 deletion JavaScript_Basics/exercise_1_using_arrays.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var array = [1, 0.16, "Random", function () {
const array = [1, 0.16, "Random", function () {
console.log("this is function in an array");
}, { Key: "Answer" }, false];

Expand Down
2 changes: 1 addition & 1 deletion JavaScript_Basics/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ function isBigEnough (value) {
return value >= 10;
}

var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
const filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// filtered is [12, 130, 44]
2 changes: 1 addition & 1 deletion JavaScript_Basics/iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Can be used as shown below:--
*/

(function (value) {
var modified = value + 4;
const modified = value + 4;
console.log(modified);
}(3));
2 changes: 1 addition & 1 deletion JavaScript_Basics/map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Let's create an array of numbers that we want to get the square of each number in the array
var numbers = [1, 2, 3, 4, 5];
const numbers = [1, 2, 3, 4, 5];

// pass a function to map
const square = numbers.map(function (num) {
Expand Down
9 changes: 4 additions & 5 deletions JavaScript_Basics/reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ the array to a single value and executes a provided function
for each value of the array (from left-to-right) and the return
value of the function is stored in an accumulator.
*/
var pokemon = ["squirtle", "charmander", "bulbasaur"];
const pokemon = ["squirtle", "charmander", "bulbasaur"];

var pokeLength =
pokemon.reduce(function (previous, current) {
return previous + current.length;
}, 0);
const pokeLength = pokemon.reduce(function (previous, current) {
return previous + current.length;
}, 0);

// Outputs 27
10 changes: 5 additions & 5 deletions JavaScript_Basics/strict_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// examples taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

// Assignment to a non-writable global
var undefined = 5; // throws a TypeError
var Infinity = 5; // throws a TypeError
const undefined = 5; // throws a TypeError
const Infinity = 5; // throws a TypeError

// Assignment to a non-writable property
var obj1 = {};
const obj1 = {};
Object.defineProperty(obj1, "x", { value: 42, writable: false });
obj1.x = 9; // throws a TypeError

// Assignment to a getter-only property
var obj2 = { get x () { return 17; } };
const obj2 = { get x () { return 17; } };
obj2.x = 5; // throws a TypeError

// Assignment to a new property on a non-extensible object
var fixed = {};
const fixed = {};
Object.preventExtensions(fixed);
fixed.newProp = "ohai"; // throws a TypeError

Expand Down
4 changes: 2 additions & 2 deletions JavaScript_Basics/this.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
console.log(this); // This gives empty object
// Output {}

var aa = 1;
const aa = 1;
console.log(global.aa); // Global scope is accessible to every where
// Output undefined

Expand All @@ -19,7 +19,7 @@ console.log(a);
// console.log(b) // Output ReferenceError: b is not defined as b is defined using let it is going to be declared only in that block

const help = () => {
var a = 4;
const a = 4;
const b = 2; // variables defined by let and const are accessible to there scope only
console.log(a); // This will not get printed unless and until function is called
};
Expand Down