├── Basic Javascript ├── 00.Introduction.md ├── 01.DataType │ ├── 01.DataType.js │ ├── 01.DataType.md │ ├── Boolean.md │ ├── LongTimeAgo.md │ ├── Numbers.md │ ├── Objects.md │ └── Strings.md ├── 02.Variables │ ├── 02.Variables.js │ └── 02.Variables.md ├── 03.Functions │ ├── 03.Functions.js │ ├── 03.Functions.md │ ├── ArrowFunctions.md │ └── Parameters_Arguments.md ├── 04.Hoisting │ ├── Hoisting.js │ └── Hoisting.md ├── 04.Loops.js ├── 05.Arrays.js ├── 06.Objects.js ├── 07.EventLoop.js ├── 08.DOM.js ├── Javascript Bootcamp Day 5.pdf └── index.html ├── Google Apps Script ├── DocumentApp.md ├── DriveApp.md ├── Intro.md ├── SpreadsheetApp.md └── Sum-Up.md ├── How Javascript Works └── How JavaScript Works.pdf └── README.md /Basic Javascript/00.Introduction.md: -------------------------------------------------------------------------------- 1 | # JAVASCRIPT BOOTCAMP 2 | This repository is exclusive to javascript bootcamp, organized at GDSC TIU. 3 | #### An introductory resource by [Gourav Ghosal](https://github.com/gourav221b), Chapter Lead, Google Developer Students Club, Techno India University. 4 | 5 | ## Table of Contents 6 | --- 7 | ### 1. Basic Javascript 8 |
9 | 10 | - [A long long time ago.....](Basic%20Javascript/01.DataType/LongTimeAgo.md) 11 | 12 | - [Data Types](Basic%20Javascript/01.DataType/01.DataType.md) 13 | - [Variables](Basic%20Javascript/02.Variables/02.Variables.md) 14 | - [Functions](Basic%20Javascript/03.Functions/03.Functions.md) 15 | 16 | - Loops 17 | - Arrays 18 | - Objects 19 | - DOM Manipulation 20 | 21 |
22 | 23 | --- 24 | 25 | ### 2. How Javascript Works 26 |
27 | 28 | - [Javascript Engine](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 29 | 30 | - [Execution Contexts](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 31 | - [Global Execution Context](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 32 | - [Function Execution Context](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 33 | - [Creation Phase](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 34 | - The Variable Object 35 | - [Hoisting](Basic%20Javascript/04.Hoisting/Hoisting.md) 36 | - Scope Chan 37 | - *this* Keyword 38 | - [Execution Phase](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 39 | - [Execution Stack](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 40 | - Event Loops 41 | 42 |
43 | 44 | --- 45 | 46 |
47 | 48 | ### 3. Advanced Javascript 49 |
50 | 51 | - Promises and Callbacks 52 | 53 | - Closures 54 | - Async and Await 55 | - OOPS 56 | - Modules 57 | - Intro to React Js 58 |
59 | 60 | --- 61 | 62 |
63 | -------------------------------------------------------------------------------- /Basic Javascript/01.DataType/01.DataType.js: -------------------------------------------------------------------------------- 1 | // STRINGS IN JAVASCRIPT : Create Concate, Compare 2 | // --------------------------------------------------------------------------------- 3 | // String is a primitive data type in JavaScript. A string is textual content. It must be enclosed in single or double quotation marks. 4 | 5 | // Example : 6 | 7 | var str1 = 'This is a string with single quotes'; 8 | var str2 = "This is a string with double quotes"; 9 | 10 | // Strings can also be treated as 0 based character arrays 11 | var str3 = "Character Array" 12 | for (let i in str3) 13 | console.log(str3[i]) 14 | 15 | // Different methods to access strings as arrays 16 | 17 | for (let i = 0; i < str3.length; i++) 18 | console.log(str3[i]) 19 | 20 | for (let i of str3) 21 | console.log(i) 22 | 23 | // --------------------------------------------------------------------------------- 24 | // Concatenation 25 | // A string is immutable in JavaScript, it can be concatenated using plus(+) operator in JavaScript. 26 | 27 | /*Think of immutability as “save as” because you know it returns a newly changed object while traditional in-place mutation would be like “save” means updating the original and letting go of an earlier state. The structure of the immutable data cannot be changed. 28 | 29 | The data would be the original one and once the object is created we can not modify its state in an immutable object.Consider the immutability concept as the human body which is not affected by the outside world.A state with peace of mind. */ 30 | 31 | var concatStr = 'This ' + "is " + 'GDSC ' + 'TIU '; 32 | console.log(concatStr); 33 | 34 | 35 | // String object 36 | // Above, we assigned a string literal to a variable. JavaScript allows you to create a String object using the new keyword, as shown below. 37 | 38 | var objStr1 = new String(); 39 | ObjStr1 = 'Hello World1'; 40 | 41 | // or 42 | 43 | var ObjStr2 = new String('Hello World2'); 44 | console.log(typeof (ObjStr1), typeof (ObjStr2)); 45 | 46 | 47 | // WARNING 48 | // Be careful while working with String object because comparison of string objects using == operator compares String objects and not the values.Consider the following example 49 | 50 | var str1 = new String('Hello World'); 51 | var str2 = new String('Hello World'); 52 | var str3 = 'Hello World'; 53 | var str4 = str1; 54 | 55 | str1 == str2; // false - because str1 and str2 are two different objects 56 | str1 == str3; // true 57 | str1 === str4; // true 58 | 59 | typeof (str1); // object 60 | typeof (str3); //string 61 | 62 | 63 | 64 | // PROPERTIES 65 | var str1 = "Some String" 66 | str1.length //11 67 | 68 | // METHODS 69 | 70 | charAt(position) 71 | charCodeAt(position) 72 | concat([string, ,]) 73 | indexOf(SearchString, Position) 74 | lastIndexOf(SearchString, Position) 75 | localeCompare(string, position) 76 | match(RegExp) 77 | replace(searchValue, replaceValue) 78 | // .......... etc 79 | 80 | 81 | 82 | 83 | // ----------------------------------------------------------------------------------------------------------------- 84 | // JavaScript Numbers: Integer, Float, Binary, Exponential, Hexadecimal, Octal 85 | // The Number is a primitive data type used for positive or negative integer, float, binary, octal, hexadecimal, and exponential values in JavaScript. 86 | 87 | // The Number type in JavaScript is double - precision 64 bit binary format like double in C# and Java.It follows the international IEEE 754 standard. 88 | 89 | // The first character in a number type must be an integer value, and it must not be enclosed in quotation marks.The following example shows the variables having different types of numbers in JavaScript. 90 | 91 | 92 | 93 | var num1 = 100; // integer 94 | var num2 = -100; //negative integer 95 | 96 | var num3 = 10.52; // float 97 | var num4 = -10.52; //negative float 98 | 99 | var num5 = 0xfff; // hexadecimal 100 | var num6 = 256e-5; // exponential 101 | var num7 = 030; // octal 102 | var num8 = 0b0010001; // binary 103 | 104 | // Number() Function in JavaScript 105 | 106 | // The Number() is a constructor function in JavaScript that converts values of other types to numbers. 107 | var i = Number('100'); 108 | var f = Number('10.5'); 109 | var b = Number('0b100'); 110 | typeof (i); // returns number 111 | typeof (f); // returns number 112 | typeof (b); // returns number 113 | 114 | // By using the new operator with the Number() function will return an object which contains constants and methods for working with numbers. 115 | var i = new Number('100'); 116 | var f = new Number('10.5'); 117 | var b = new Number('0b100'); 118 | typeof (i); // returns object 119 | typeof (f); // returns object 120 | typeof (b); // returns object 121 | 122 | 123 | // Compare Numbers 124 | // Be careful while comparing numbers using == or === operators.The == operator compares object references and not the values whereas the === operator compare values.The following example compares numbers created by different ways. 125 | 126 | var num1 = new Number(100); 127 | var num2 = Number('100'); 128 | var num3 = 100; 129 | 130 | num1 == num2; // true 131 | num1 === num2; // false 132 | 133 | num2 == num3;//true 134 | num2 === num3; // true 135 | 136 | num1 == num3;//true 137 | num1 === num3;//false 138 | 139 | 140 | // Number Properties 141 | // The Number type includes some default properties.JavaScript treats primitive values as objects, so all the properties and methods are applicable to both literal numbers and number objects. 142 | 143 | Number.MAX_VALUE; //1.7976931348623157e+308 144 | Number.MIN_VALUE; //5e-324 145 | Number.NEGATIVE_INFINITY; //-Infinity 146 | Number.POSITIVE_INFINITY; //Infinity 147 | Number.NaN;//NaN -------------------------------------------------------------------------------- /Basic Javascript/01.DataType/01.DataType.md: -------------------------------------------------------------------------------- 1 | # Data Types In Javascript 2 | 3 | Data types in Js are similar to other programming languages (C# or Java). 4 | Javascript minimizes the need to specify the type of variable. 5 | The following example shows how a variable can be assigned any type of value. 6 |
7 |
8 | 9 | ``` 10 | var testVariable = 1; // numeric value 11 | 12 | testVariable = 'one'; // string value 13 | 14 | testVariable = 1.1; // decimal value 15 | 16 | testVariable = true; // Boolean value 17 | 18 | testVariable = null; // null value 19 | ``` 20 | 21 | 22 | ___ 23 | ### JavaScript includes primitive and non-primitive data types as per latest ECMAScript 5.1. 24 |
25 |
26 | 27 | ## 1. Primitive Data Types 28 | 29 | These are the lowest level of the data value in JavaScript. The ``` typeof ``` 30 | operator can be used with primitive data types to know the type of a value. 31 | 32 | Examples : 33 | - ```String``` : String is a textual content wrapped inside ' ' or " " or ` ` (tick sign). 34 | 35 | - ```Number``` : Number is a numeric value. Example: 100, 4521983, etc. 36 | - ```BigInt``` : BigInt is a numeric value in the arbitrary precision format. Example: 453889879865131n, 200n, etc. 37 | - ```Boolean``` : Boolean is a logical data type that has only two values, ```true``` or ```false```. 38 | ```Null``` : A null value denotes an absense of value. Example: ```var str = null;``` 39 | - ```Undefined``` : undefined is the default value of a variable that has not been assigned any value. 40 |
41 |
42 | 43 | ## 2. Non Primitive Data Types 44 | - ```Object```: An object holds multiple values in terms of properties and methods. 45 | 46 | ``` 47 | Example: 48 | var person = { 49 | firstName: "James", 50 | lastName: "Bond", 51 | age: 15 52 | }; 53 | ``` 54 | - ```Date```: Date object represents date & time including days, months, years, hours, minutes, seconds and milliseconds. 55 | ``` 56 | Example: 57 | var today = new Date("25 July 2021"); 58 | ``` 59 | - ```Array``` : An array stores multiple values using special syntax. 60 | ``` 61 | Example: 62 | var nums = [1, 2, 3, 4]; 63 | ``` 64 | 65 | 66 | ## For Detailed Descriptions visit the following Links: 67 | - [code](01.DataType.js) 68 | - [Strings](Strings.md) 69 | - [Numbers](Numbers.md) 70 | - [Boolean](Boolean.md) 71 | - [Objects](Objects.md) 72 | --- -------------------------------------------------------------------------------- /Basic Javascript/01.DataType/Boolean.md: -------------------------------------------------------------------------------- 1 | # JavaScript Booleans 2 | The boolean (not Boolean) is a primitive data type in JavaScript. It can have only two values: true or false. It is useful in controlling program flow using conditional statements like if else, switch, while loop, etc. 3 | 4 | The followings are boolean variables. 5 | 6 | ### Example: boolean Variables 7 | ``` 8 | var YES = true; 9 | 10 | var NO = false; 11 | ``` 12 | 13 | The following example demonstrates how a boolean value controls the program flow using the if condition. 14 | 15 | ### Example: Boolean 16 | ``` 17 | var YES = true; 18 | var NO = false; 19 | 20 | if(YES) 21 | { 22 | alert("This code block will be executed"); 23 | } 24 | 25 | if(NO) 26 | { 27 | alert("This code block will not be executed"); 28 | } 29 | ``` 30 | 31 | The comparison expressions return boolean values to indicate whether the comparison is true or false. For example, the following expressions return boolean values. 32 | 33 | ### Example: boolean Expressions 34 | ``` 35 | var a = 10, b = 20; 36 | 37 | var result = 1 > 2; // false 38 | 39 | result = a < b; // true 40 | 41 | result = a > b; // false 42 | 43 | result = a + 20 > b + 5; // true 44 | ``` 45 | 46 | ## Boolean Function 47 | JavaScript provides the Boolean() function that converts other types to a boolean type. The value specified as the first parameter will be converted to a boolean value. The Boolean() will return true for any non-empty, non-zero, object, or array. 48 | 49 | ### Example: Boolean() Function 50 | ``` 51 | var a = 10, b = 20; 52 | 53 | var b1 = Boolean('Hello'); // true 54 | 55 | var b2 = Boolean('h'); // true 56 | 57 | var b3 = Boolean(10); // true 58 | 59 | var b4 = Boolean([]); // true 60 | 61 | var b5 = Boolean(a + b); // true 62 | ``` 63 | 64 | If the first parameter is 0, -0, null, false, NaN, undefined, '' (empty string), or no parameter passed then the Boolean() function returns false. 65 | 66 | ### Example: Boolean() Function 67 | ``` 68 | var b1 = Boolean(''); // false 69 | 70 | var b2 = Boolean(0); // false 71 | 72 | var b3 = Boolean(null); // false 73 | 74 | var a; 75 | var b4 = Boolean(a); // false 76 | ``` 77 | 78 | The new operator with the Boolean() function returns a Boolean object. 79 | 80 | ### Example: Boolean Object 81 | ``` 82 | var bool = new Boolean(true); 83 | 84 | alert(bool); // true 85 | Any boolean object, when passed in a conditional statement, will evaluate to true. 86 | ``` 87 | ### Example: Boolean Object in Condition 88 | ``` 89 | var bool = new Boolean(false); 90 | 91 | if(bool){ 92 | alert('This will be executed.'); 93 | } 94 | ``` 95 | ## Boolean vs boolean 96 | The new Boolean() will return a Boolean object, whereas it returns a boolean without the new keyword. The boolean (lower case) is the primitive type, whereas Boolean (upper case) is an object in JavaScript. Use the typeof operator to check the types. 97 | 98 | ### Example: Boolean vs boolean 99 | ``` 100 | var b1 = new Boolean(true); 101 | var b2 = true; 102 | 103 | typeof b1; // object 104 | typeof b2; // boolean 105 | ``` 106 | ## Boolean Methods 107 | Primitive or Boolean object includes following methods. 108 | 109 | |Method| Description| 110 | |-----|----| 111 | |toLocaleString()| Returns string of boolean value in local browser environment.| 112 | 113 | ### Example: 114 | ``` var result = (1 > 2); result.toLocaleString(); // returns "false" 115 | 116 | toString() Returns a string of Boolean. 117 | ``` 118 | 119 | ### Example: 120 | ``` 121 | var result = (1 > 2); result.toString(); // returns "false" 122 | valueOf() Returns the value of the Boolean object. 123 | ``` 124 | 125 | ### Example: 126 | ``` 127 | var result = (1 > 2); result.valueOf(); // returns false 128 | ``` -------------------------------------------------------------------------------- /Basic Javascript/01.DataType/LongTimeAgo.md: -------------------------------------------------------------------------------- 1 | # JavaScript History 2 | JavaScript was invented by Brendan Eich in 1995. 3 | 4 | It was developed for Netscape 2, and became the ECMA-262 standard in 1997. 5 | 6 | After Netscape handed JavaScript over to ECMA, the Mozilla foundation continued to develop JavaScript for the Firefox browser. Mozilla's latest version was 1.8.5. (Identical to ES5). 7 | 8 | Internet Explorer (IE4) was the first browser to support ECMA-262 Edition 1 (ES1). 9 |
10 |
11 | 12 | # The ECMA Technical Committee 39 13 | In 1996, Netscape and Brendan Eich took JavaScript to the ECMA international standards organization, and a technical committee (TC39) was created to develop the language. 14 | 15 | ECMA-262 Edition 1 was released in June 1997. 16 | 17 | # From ES4 to ES6 18 | When the TC39 committee got together in Oslo in 2008, to agree on ECMAScript 4, they were divided into 2 very different camps: 19 | 20 | The ECMAScript 3.1 Camp: 21 | Microsoft and Yahoo who wanted an incremental upgrade from ES3. 22 | 23 | The ECMAScript 4 Camp: 24 | Adobe, Mozilla, Opera, and Google who wanted a massive ES4 upgrade. 25 | 26 | August 13 2008, Brendan Eich wrote an email: 27 | 28 | >It's no secret that the JavaScript standards body, Ecma's Technical Committee 39, has been split for over a year, with some members favoring ES4, a major fourth edition to ECMA-262, and others advocating ES3.1 based on the existing ECMA-262 Edition 3 (ES3) specification. Now, I'm happy to report, the split is over. 29 | 30 | The solution was to work together: 31 | 32 | >ECMAScript 4 was renamed to ES5 33 | ES5 should be an incremental upgrade of ECMAScript 3. 34 | Features of ECMAScript 4 should be picked up in later versions. 35 | TC39 should develop a new major release, bigger in scope than ES5. 36 | The planned new release (ES6) was codenamed "Harmony" (Because of the split it created?). 37 | 38 | >ES5 was a huge success. It was released in 2009, and all major browsers (including Internet Explorer) were fully compliant by July 2013: -------------------------------------------------------------------------------- /Basic Javascript/01.DataType/Numbers.md: -------------------------------------------------------------------------------- 1 | # JavaScript Numbers: Integer, Float, Binary, Exponential, Hexadecimal, Octal 2 | The Number is a primitive data type used for positive or negative integer, float, binary, octal, hexadecimal, and exponential values in JavaScript. 3 | 4 | The Number type in JavaScript is double - precision 64 bit binary format like double in C# and Java.It follows the international IEEE 754 standard. 5 | 6 | The first character in a number type must be an integer value, and it must not be enclosed in quotation marks.The following example shows the variables having different types of numbers in JavaScript. 7 | 8 | ``` 9 | var num1 = 100; // integer 10 | var num2 = -100; //negative integer 11 | 12 | var num3 = 10.52; // float 13 | var num4 = -10.52; //negative float 14 | 15 | var num5 = 0xfff; // hexadecimal 16 | var num6 = 256e-5; // exponential 17 | var num7 = 030; // octal 18 | var num8 = 0b0010001; // binary 19 | ``` 20 | 21 | ## Number() Function in JavaScript 22 | 23 | The Number() is a constructor function in JavaScript that converts values of other types to numbers. 24 | ``` 25 | var i = Number('100'); 26 | var f = Number('10.5'); 27 | var b = Number('0b100'); 28 | typeof (i); // returns number 29 | typeof (f); // returns number 30 | typeof (b); // returns number 31 | ``` 32 | 33 | By using the new operator with the Number() function will return an object which contains constants and methods for working with numbers. 34 | ``` 35 | var i = new Number('100'); 36 | var f = new Number('10.5'); 37 | var b = new Number('0b100'); 38 | typeof (i); // returns object 39 | typeof (f); // returns object 40 | typeof (b); // returns object 41 | ``` 42 | 43 | 44 | ## Compare Numbers 45 | Be careful while comparing numbers using ```==``` or ```=== ``` operators.The ```==``` operator compares object references and not the values whereas the ```===``` operator compare values.The following example compares numbers created by different ways. 46 | ``` 47 | var num1 = new Number(100); 48 | var num2 = Number('100'); 49 | var num3 = 100; 50 | 51 | num1 == num2; // true 52 | num1 === num2; // false 53 | 54 | num2 == num3;//true 55 | num2 === num3; // true 56 | 57 | num1 == num3;//true 58 | num1 === num3;//false 59 | ``` 60 | 61 | ## Number Properties 62 | The Number type includes some default properties.JavaScript treats primitive values as objects, so all the properties and methods are applicable to both literal numbers and number objects. 63 | ``` 64 | Number.MAX_VALUE; //1.7976931348623157e+308 65 | Number.MIN_VALUE; //5e-324 66 | Number.NEGATIVE_INFINITY; //-Infinity 67 | Number.POSITIVE_INFINITY; //Infinity 68 | Number.NaN; //NaN 69 | ``` 70 | 71 | ## Number Methods 72 | 73 | | Method | Description| 74 | | ------ | ------ | 75 | |toExponential(fractionDigits) | Returns exponential value as a string. | 76 | | toFixed(fractionDigits) | Returns string of decimal value of a number based on specified fractionDigits. | 77 | |toLocaleString() | Returns a number as a string value according to a browser's locale settings. | 78 | |toPrecision(precisionNumber) | Returns number as a string with specified total digits.| 79 | |toString()| Returns the string representation of the number value. 80 | |valueOf()| Returns the value of Number object.| 81 | -------------------------------------------------------------------------------- /Basic Javascript/01.DataType/Objects.md: -------------------------------------------------------------------------------- 1 | # JavaScript Objects: Create Objects, Access Properties & Methods 2 | Here you will learn objects, object literals, Object() constructor function, and access object in JavaScript. 3 | 4 | You learned about primitive and structured data types in JavaScript. An object is a non-primitive, structured data type in JavaScript. Objects are same as variables in JavaScript, the only difference is that an object holds multiple values in terms of properties and methods. 5 | 6 | In JavaScript, an object can be created in two ways: 7 | 1. using Object Literal/Initializer Syntax 8 | 2. using the Object() Constructor function with the new keyword. Objects created using any of these methods are the same. 9 | 10 | The following example demonstrates creating objects using both ways. 11 | 12 | ### Example: JavaScript Objects 13 | ``` 14 | var p1 = { name:"Steve" }; // object literal syntax 15 | 16 | var p2 = new Object(); // Object() constructor function 17 | p2.name = "Steve"; // property 18 | ``` 19 | Above, p1 and p2 are the names of objects. 20 |
Objects can be declared same as variables using var or let keywords. The p1 object is created using the object literal syntax (a short form of creating objects) with a property named name. The p2 object is created by calling the Object() constructor function with the new keyword. The ```p2.name = "Steve";``` attach a property name to p2 object with a string value "Steve". 21 | 22 | ### Create Object using Object Literal Syntax 23 | The object literal is a short form of creating an object. Define an object in the { } brackets with key:value pairs separated by a comma. The key would be the name of the property and the value will be a literal value or a function. 24 | 25 | ``` 26 | Syntax: 27 | 28 | var = { key1: value1, key2: value2,...}; 29 | ``` 30 | 31 | The following example demonstrates objects created using object literal syntax. 32 | 33 | ### Example: Object Literal Syntax 34 | ``` 35 | var emptyObject = {}; // object with no properties or methods 36 | 37 | var person = { firstName: "John" }; // object with single property 38 | 39 | // object with single method 40 | var message = { 41 | showMessage: function (val) { 42 | alert(val); 43 | } 44 | }; 45 | 46 | // object with properties & method 47 | var person = { 48 | firstName: "James", 49 | lastName: "Bond", 50 | age: 15, 51 | getFullName: function () { 52 | return this.firstName + ' ' + this.lastName 53 | } 54 | }; 55 | 56 | ``` 57 | **Note: that the whole key-value pair must be declared. Declaring only a key without a value is invalid, as shown below.** 58 | 59 | ### Example: Wrong Syntax 60 | ``` 61 | var person = { firstName }; 62 | 63 | var person = { getFullName: }; 64 | ``` 65 | ### Create Objects using Objects() Constructor 66 | 67 | Another way of creating objects is using the Object() constructor function using the new keyword. Properties and methods can be declared using the dot notation .property-name or using the square brackets ["property-name"], as shown below. 68 | 69 | ### Example: Create Object using Object() Constructor 70 | ``` 71 | var person = new Object(); 72 | 73 | // Attach properties and methods to person object 74 | person.firstName = "James"; 75 | person["lastName"] = "Bond"; 76 | person.age = 25; 77 | person.getFullName = function () { 78 | return this.firstName + ' ' + this.lastName; 79 | }; 80 | ``` 81 | 82 | An object can have variables as properties or can have computed properties, as shown below. 83 | 84 | ### Example: Variables as Object Properties 85 | ``` 86 | var firstName = "James"; 87 | var lastName = "Bond"; 88 | var person = { firstName, lastName } 89 | ``` 90 | ### Access JavaScript Object Properties & Methods 91 | An object's properties can be accessed using the dot notation obj.property-name or the square brackets obj["property-name"]. However, method can be invoked only using the dot notation with the parenthesis, obj.method-name(), as shown below. 92 | 93 | ### Example: Access JS Object 94 | ``` 95 | var person = { 96 | firstName: "James", 97 | lastName: "Bond", 98 | age: 25, 99 | getFullName: function () { 100 | return this.firstName + ' ' + this.lastName 101 | } 102 | }; 103 | 104 | person.firstName; // returns James 105 | person.lastName; // returns Bond 106 | 107 | person["firstName"];// returns James 108 | person["lastName"];// returns Bond 109 | 110 | person.getFullName(); // calling getFullName function 111 | ``` 112 | In the above example, the person.firstName access the firstName property of a person object. The person["firstName"] is another way of accessing a property. An object's methods can be called using () operator e.g. person.getFullName(). JavaScript engine will return the function definition if accessed method without the parenthesis. 113 | 114 | Accessing undeclared properties of an object will return undefined. If you are not sure whether an object has a particular property or not, then use the hasOwnProperty() method before accessing them, as shown below. 115 | 116 | ### Example: hasOwnProperty() 117 | ``` 118 | var person = new Object(); 119 | 120 | person.firstName; // returns undefined 121 | 122 | if(person.hasOwnProperty("firstName")){ 123 | person.firstName; 124 | } 125 | ``` 126 | The properties and methods will be available only to an object where they are declared. 127 | 128 | ### Example: Object Constructor 129 | ``` 130 | var p1 = new Object(); 131 | p1.firstName = "James"; 132 | p1.lastName = "Bond"; 133 | 134 | var p2 = new Object(); 135 | p2.firstName; // undefined 136 | p2.lastName; // undefined 137 | 138 | 139 | p3 = p1; // assigns object 140 | p3.firstName; // James 141 | p3.lastName; // Bond 142 | p3.firstName = "Sachin"; // assigns new value 143 | p3.lastName = "Tendulkar"; // assigns new value 144 | ``` 145 | ### Enumerate Object's Properties 146 | Use the for in loop to enumerate an object, as shown below. 147 | 148 | ### Example: Access Object Keys 149 | ``` 150 | var person = new Object(); 151 | person.firstName = "James"; 152 | person.lastName = "Bond"; 153 | 154 | for(var prop in person){ 155 | alert(prop); // access property name 156 | alert(person[prop]); // access property value 157 | }; 158 | 159 | ``` 160 | ### Pass by Reference 161 | Object in JavaScript passes by reference from one function to another. 162 | 163 | ### Example: JS Object Passes by Reference 164 | ``` 165 | function changeFirstName(per) 166 | { 167 | per.firstName = "Steve"; 168 | } 169 | 170 | var person = { firstName : "Bill" }; 171 | 172 | changeFirstName(person) 173 | 174 | person.firstName; // returns Steve 175 | ``` 176 | ### Nested Objects 177 | An object can be a property of another object. It is called a nested object. 178 | 179 | ### Example: Nested JS Objects 180 | ```var person = { 181 | firstName: "James", 182 | lastName: "Bond", 183 | age: 25, 184 | address: { 185 | id: 1, 186 | country:"UK" 187 | } 188 | }; 189 | 190 | person.address.country; // returns "UK" 191 | ``` 192 | 193 | Points to Remember : 194 | 1. JavaScript object is a standalone entity that holds multiple values in terms of properties and methods. 195 | 2. Object property stores a literal value and method represents function. 196 | 3. An object can be created using object literal or object constructor syntax. 197 | 198 | var person = { 199 | firstName: "James", 200 | lastName: "Bond", 201 | age: 25, 202 | getFullName: function () { 203 | return this.firstName + ' ' + this.lastName 204 | } 205 | }; 206 | Object constructor: 207 | var person = new Object(); 208 | 209 | person.firstName = "James"; 210 | person["lastName"] = "Bond"; 211 | person.age = 25; 212 | person.getFullName = function () { 213 | return this.firstName + ' ' + this.lastName; 214 | }; 215 | 216 | 4. Object properties and methods can be accessed using dot notation or [ ] bracket. 217 | 5. An object is passed by reference from one function to another. 218 | 6. An object can include another object as a property. 219 | -------------------------------------------------------------------------------- /Basic Javascript/01.DataType/Strings.md: -------------------------------------------------------------------------------- 1 | # STRINGS IN JAVASCRIPT : Create Concate, Compare 2 | 3 | String is a primitive data type in JavaScript. A string is textual content. It must be enclosed in single or double quotation marks. 4 | 5 | Example : 6 | ``` 7 | var str1 = 'This is a string with single quotes'; 8 | var str2 = "This is a string with double quotes"; 9 | ``` 10 | 11 | Strings can also be treated as 0 based character arrays 12 | ``` 13 | var str3 = "Character Array" 14 | for (let i in str3) 15 | console.log(str3[i]) 16 | ``` 17 | 18 | Different methods to access strings as arrays 19 | ``` 20 | for (let i = 0; i < str3.length; i++) 21 | console.log(str3[i]) 22 | 23 | for (let i of str3) 24 | console.log(i) 25 | ``` 26 | --- 27 | ### Concatenation 28 | A string is immutable in JavaScript, it can be concatenated using plus(+) operator in JavaScript. 29 | 30 | Think of immutability as “save as” because you know it returns a newly changed object while traditional in-place mutation would be like “save” means updating the original and letting go of an earlier state. The structure of the immutable data cannot be changed. 31 | 32 | The data would be the original one and once the object is created we can not modify its state in an immutable object.Consider the immutability concept as the human body which is not affected by the outside world.A state with peace of mind. 33 | ``` 34 | var concatStr = 'This ' + "is " + 'GDSC ' + 'TIU '; 35 | concatStr // This is GDSC TIU 36 | ``` 37 | 38 | ### String object 39 | Above, we assigned a string literal to a variable. JavaScript allows you to create a String object using the new keyword, as shown below. 40 | 41 | ``` 42 | var objStr1 = new String(); 43 | ObjStr1 = 'Hello World1'; 44 | 45 | // or 46 | 47 | var ObjStr2 = new String('Hello World2'); 48 | console.log(typeof (ObjStr1), typeof (ObjStr2)); 49 | ``` 50 | 51 | ## **WARNING !!** 52 | Be careful while working with String object because comparison of string objects using ``` ==``` operator compares String objects and not the values.Consider the following example 53 | ``` 54 | var str1 = new String('Hello World'); 55 | var str2 = new String('Hello World'); 56 | var str3 = 'Hello World'; 57 | var str4 = str1; 58 | 59 | str1 == str2; // false - because str1 and str2 are two different objects 60 | str1 == str3; // true 61 | str1 === str4; // true 62 | 63 | typeof (str1); // object 64 | typeof (str3); //string 65 | 66 | ``` 67 | 68 | ## PROPERTIES 69 | length : returns the length of the string in ```Number``` 70 | ``` 71 | var str1 = "Some String" 72 | str1.length //11 73 | ``` 74 | ## METHODS 75 | 76 | | Method | Description | 77 | | ----------- | ----------- | 78 | | charAt(position) | Returns the character at the specified position (in Number) | 79 | | charCodeAt(position) | Returns a number indicating the Unicode value of the character at the given position (in Number). | 80 | | concat([string,,]) | Joins specified string literal values (specify multiple strings separated by comma) and returns a new string. | 81 | | indexOf(SearchString, Position) | Returns the index of first occurrence of specified String starting from specified number index. Returns -1 if not found. | 82 | | lastIndexOf(SearchString, Position) | Returns the last occurrence index of specified SearchString, starting from specified position. Returns -1 if not found. | 83 | | localeCompare(string,position) | Compares two strings in the current locale. | 84 | | match(RegExp) | Search a string for a match using specified regular expression. Returns a matching array. | 85 | | match(RegExp) | Search a string for a match using specified regular expression. Returns a matching array. | 86 | | replace(searchValue, replaceValue) | Search specified string value and replace with specified replace Value string and return new string. Regular expression can also be used as searchValue. | 87 | | replace(searchValue, replaceValue) | Search specified string value and replace with specified replace Value string and return new string. Regular expression can also be used as searchValue. | 88 | | slice(startNumber, endNumber) | Extracts a section of a string based on specified starting and ending index and returns a new string. | 89 | | split(separatorString, limitNumber) | Splits a String into an array of strings by separating the string into substrings based on specified separator. Regular expression can also be used as separator. | 90 | | substr(start, length) | Returns the characters in a string from specified starting position through the specified number of characters (length). | 91 | | substring(start, end) | Returns the characters in a string between start and end indexes. | 92 | | toLocaleLowerCase() | Converts a string to lower case according to current locale. | 93 | | toLocaleUpperCase() | Converts a string to Upper case according to current locale. | 94 | | toLowerCase() | Returns lower case string value.| 95 | | toLowerCase() | Returns lower case string value.| 96 | |toString() | Returns the value of String object.| 97 | | toUpperCase() | Returns upper case string value.| 98 | |valueOf()| Returns the primitive value of the specified string object.| 99 | 100 | 101 | 102 | 103 | 104 | 105 | ## SUMMARY 106 | 107 | - JavaScript string must be enclosed in double or single quotes (" " or ' '). 108 | - String can be assigned to a variable using = operator. 109 | - Multiple strings can be concatenated using + operator. 110 | - A string can be treated as character array. 111 | - Use back slash (\) to include quotation marks inside string. 112 | - String objects can be created using new keyword. e.g. ``` var str = new String();``` 113 | - String methods are used to perform different task on strings. 114 | -------------------------------------------------------------------------------- /Basic Javascript/02.Variables/02.Variables.js: -------------------------------------------------------------------------------- 1 | // HOISTING IN JAVASCRIPT 2 | // --------------------------------------------------------------------------------- 3 | // * Differnce Between Var and let 4 | 5 | //! var is function scoped 6 | 7 | // variable a cannot be used here 8 | function greet() { 9 | // variable a can be used here 10 | var a = 'hello'; 11 | console.log(a); 12 | } 13 | // variable a cannot be used here 14 | 15 | greet(); 16 | 17 | // OR 18 | 19 | function greet() { 20 | let a = 'hello'; 21 | 22 | // variable b can be used here but will be undefined 23 | console.log(b); 24 | if (a == 'hello') { 25 | // variable b can be used here 26 | var b = 'world'; 27 | console.log(a + ' ' + b); 28 | } 29 | 30 | // variable b can be used here 31 | console.log(a + ' ' + b); 32 | } 33 | 34 | greet(); 35 | 36 | // In the above program, the variable a is declared with var. The variable a can be used anywhere inside the function greet. 37 | 38 | //! let is block-scoped 39 | 40 | function greet() { 41 | let a = 'hello'; 42 | 43 | // variable b cannot be used here 44 | if (a == 'hello') { 45 | // variable b can be used here 46 | let b = 'world'; 47 | console.log(a + ' ' + b); 48 | } 49 | 50 | // variable b cannot be used here 51 | console.log(a + ' ' + b); // error 52 | } 53 | 54 | greet(); 55 | 56 | // Output 57 | /* 58 | hello world 59 | Uncaught ReferenceError: b is not defined 60 | */ 61 | 62 | // ! let doesn't allow to redeclare Variables 63 | //? 1. A variable declared with var can be redeclared again. For example, 64 | 65 | var a = 5; // 5 66 | var a = 3; // 3 67 | 68 | //? A variable declared with let cannot be redeclared within the same block or same scope. For example, 69 | 70 | let a = 5; 71 | let a = 3; // error 72 | 73 | //? 2. Redeclaring a variable with var in a different scope or block changes the value of the outer variable too. For example, 74 | var a = 5; 75 | console.log('before the block', a); // 5 76 | { 77 | var a = 3; 78 | console.log('in the block', a); // 3 79 | } 80 | console.log('after the block', a); // 3 81 | 82 | //? Redeclaring a variable with let in a different scope or block treats that variable as a different variable. And the value of a variable outside does not change. For example, 83 | 84 | let a = 5; 85 | console.log('before the block', a); // 5 86 | { 87 | let a = 3; 88 | console.log('in the block', a); // 3 89 | } 90 | console.log('after the block', a); // 5 91 | 92 | //! let Doesn't Allow Hoisting 93 | //? Shown Later 94 | 95 | // --------------------------------------------------------------------------------- 96 | // Global and Local Variables 97 | var data = 200; // global variable 98 | 99 | function first() { 100 | var localData = 400; 101 | 102 | console.log(data); 103 | console.log(localData); 104 | } 105 | 106 | function second() { 107 | console.log(data); 108 | console.log(localData); // Will give error saying 'localData not defined' 109 | } 110 | 111 | first(); //calling JavaScript function 112 | 113 | second(); 114 | -------------------------------------------------------------------------------- /Basic Javascript/02.Variables/02.Variables.md: -------------------------------------------------------------------------------- 1 | # Variables In Javascript 2 | 3 | ## What is a Variable? 4 | A variable is a container for a value, like a number we might use in a sum, or a string that we might use as part of a sentence.
5 | Let's look at a simple example: 6 |
7 |
8 | 9 | ``` 10 | var value = "Hello World"; 11 | var x = 10; 12 | ``` 13 | --- 14 | 15 | - The value stored in a variable can be changed during program execution. 16 | - A variable is only a name given to a memory location, all the operations done on the variable effects that memory location. 17 | - In JavaScript, all the variables must be declared before they can be used. 18 | 19 | Before ES2015 (ES6), JavaScript variables were solely declared using the var keyword followed by the name of the variable and semi-colon. 20 | 21 | After ES2015 (ES6), we now have two new variable containers: ***let*** and ***const***. 22 | 23 | --- 24 | 25 | ## Declaring a Variable 26 | There are 3 ways to Declare a JavaScript Variable in ES6 : 27 | 28 | - Using `var` 29 | - Using `let` 30 | - Using `const` 31 | 32 |
33 | 34 | 35 | ### Using `var` 36 | ``` 37 | var name; // undefined 38 | var name = "Souradeep"; 39 | name = "< Whatever Your Name is >"; 40 | 41 | var num = 10; 42 | 43 | var sum = 5 + 10 + 1; 44 | ``` 45 | 46 | ### Using `let` 47 | ``` 48 | let x; // undefined 49 | let name = 'Souradeep'; 50 | 51 | let age = 22; 52 | age = 41; //Works same as var. 53 | ``` 54 | 55 | ### Using `const` 56 | ``` 57 | const name = 'Souradeep'; 58 | name = 'Mikhail'; // will give Assignment to constant variable error. 59 | ``` 60 | 61 | ## Difference Between `Let` and `Var` 62 | 63 | | let | var | 64 | | :----------------------------------------: | :--------------------------------: | 65 | | let is block-scoped. | var is function scoped. | 66 | | let does not allow to redeclare variables. | var allows to redeclare variables. | 67 | | Hoisting does not occur in let. | Hoisting occurs in var. | 68 | 69 | --- 70 | ### There are two types of variables in JavaScript : **local variable** and **global variable**. 71 |
72 | 73 | ## JavaScript local variable 74 | A JavaScript local variable is declared inside block or function. It is accessible within the function or block only. For example: 75 | ``` 76 | function abc() { 77 | var x = 10; // local variable 78 | } 79 | 80 | If (10 < 13) { 81 | var y = 20; // Also a local variable 82 | } 83 | ``` 84 | 85 |
86 | 87 | ## JavaScript global variable 88 | A JavaScript global variable is accessible from any function. A variable i.e. declared outside the function or declared with window object is known as global variable. For example: 89 | 90 | 91 | ``` 92 | var data=200; // global variable 93 | 94 | function first(){ 95 | var localData = 400; 96 | 97 | console.log(data); 98 | console.log(localData); 99 | } 100 | function second(){ 101 | console.log(data); 102 | console.log(localData); // Will give error saying 'localData not defined' 103 | } 104 | 105 | first(); //calling JavaScript function 106 | 107 | second(); 108 | ``` 109 |
110 |
-------------------------------------------------------------------------------- /Basic Javascript/03.Functions/03.Functions.js: -------------------------------------------------------------------------------- 1 | // function testFunc(parameter1) { 2 | // parameter1.firstName = parameter1.firstName + ' ' + parameter1.lastName; 3 | // return parameter1.firstName; 4 | // } 5 | 6 | // var person = { 7 | // firstName: 'James', 8 | // lastName: 'Bond', 9 | // age: 25, 10 | // }; 11 | 12 | // console.log(testFunc(person)); 13 | // console.log(person); 14 | // console.log('argument1 ->', argument1); 15 | // console.log('argument2 ->', argument2); 16 | // console.log('argument3 ->', argument3); 17 | 18 | // var x = sumOfNumbers(1, 123, 500, 115, 44); 19 | 20 | // function sumOfNumbers() { 21 | // let sum = 0; 22 | // for (let i = 0; i < arguments.length; i++) { 23 | // console.log(arguments[i]); 24 | // } 25 | // } 26 | 27 | // console.log(x); 28 | 29 | function map(func, a) { 30 | const result = new Array(a.length); 31 | for (let i = 0; i < a.length; i++) { 32 | result[i] = func(a[i]); 33 | } 34 | return result; 35 | } 36 | 37 | const f = function (x) { 38 | return x * x * x; 39 | }; 40 | 41 | const numbers = [0, 1, 2, 5, 10]; 42 | const cube = map(f, numbers); 43 | console.log(cube); 44 | -------------------------------------------------------------------------------- /Basic Javascript/03.Functions/03.Functions.md: -------------------------------------------------------------------------------- 1 | # Functions In Javascript 2 | 3 | ## What is a Function? 4 | A function in JavaScript is similar to a procedure - a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output. 5 | 6 | In simpler words, *A JavaScript function is a block of code designed to perform a particular task.* 7 |
8 |
9 |
10 | 11 | ## Defining Functions 12 | 13 | ## **Function Definition Syntax** 14 | 15 | A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses (). 16 | 17 | ``` 18 | function name(parameter1, parameter2, parameter3) { // any number of parameters 19 | 20 | // code to be executed 21 | 22 | } 23 | ``` 24 |
25 | Lets take an example: 26 | 27 |
28 | 29 | ``` 30 | function areaOfSquare(side) { 31 | return side * side; 32 | } 33 | ``` 34 | Here, the function `areaOfSquare` takes one parameter, called `side`. The function consists of one statement that says to return the parameter of the function multiplied by itself to calculate the area of the square. The statement `return` specifies the value returned by the function. 35 | 36 |
37 | 38 | ## Parameters and Arguments 39 | - [Parameters](Parameters_Arguments.md) 40 | 41 |
42 | 43 | ## **Function Invocation** 44 | 45 | The code inside a function is executed when it is *invoked* (or **called**). 46 | 47 | *Defining* a function does not execute it. Defining it names the function and specifies what to do when the function is called. 48 | 49 | Calling the function actually performs the specified actions with the indicated parameters. For example, if you define the function areaOfSquare, you could call it as follows: 50 | 51 | ``` 52 | function areaOfSquare(side) { // Function Definition 53 | return side * side; 54 | } 55 | 56 | areaOfSquare(5); // Function Call 57 | ``` 58 | 59 | To actually use the value returned by the function, We have to either store it in a variable or use it in a expression. 60 | 61 | ``` 62 | const side5 = areaOfSquare(5); // Storing returned value in variable 63 | const side 10 = areaOfSquare(10); 64 | 65 | const sumOfAreas = areaOfSquare(6) * areaOfSquare(8); // Using returned value in a expression 66 | ``` 67 | 68 | ## Anonymous Functions 69 | Anonymous Function is a function that does not have any name associated with it. Normally we use the function keyword before the function name to define a function in JavaScript, however, in anonymous functions in JavaScript, we use only the function keyword without the function name. 70 | 71 | 72 | An anonymous function is not accessible after its initial creation, it can only be accessed by a variable it is stored in as a function as a value. An anonymous function can also have multiple arguments, but only one expression. 73 | 74 | ## **Function Expressions** 75 | 76 | Function Expression allows us to create an anonymous function which doesn’t have any function name which is the main difference between Function Expression and Function Declaration. 77 | 78 | A function expression can be used as an **IIFE *(Immediately Invoked Function Expression)*** which runs as soon as it is defined. 79 | 80 | ``` 81 | (function () { 82 | // … 83 | })(); 84 | ``` 85 | 86 | A function expression has to be stored in a variable and can be accessed using variableName. 87 | 88 | ``` 89 | const getRectArea = function(width, height) { // Function Expression 90 | return width * height; 91 | }; 92 | 93 | console.log(getRectArea(3, 4)); 94 | ``` 95 | 96 | Function expressions are convenient when passing a function as an argument to another function. 97 | 98 | ## Higher Order Functions 99 | A higher order function is a function that takes a function as an argument, or returns a function. 100 | 101 | Higher order functions provide a higher level of abstraction than typical functions. 102 | 103 | 104 | Lets take an example of adding a number to an array without using higher order functions: 105 | ``` 106 | const numbers = [1, 2, 3, 4, 5]; 107 | 108 | function addOne(array) { 109 | for (let i = 0; i < array.length; i++) { 110 | console.log(array[i] + 1); 111 | } 112 | } 113 | 114 | addOne(numbers); 115 | ``` 116 | The function addOne() accepts an array, adds one to each number in the array, and displays it in the console. The original values remain unchanged in the array, but the function is doing something for each value. 117 | 118 | 119 | However, using what may be the most common higher order function, `forEach()`, we can simplify this process: 120 | ``` 121 | const numbers = [1, 2, 3, 4, 5]; 122 | 123 | numbers.forEach((number) => console.log(number + 1)); 124 | ``` 125 | You've noticed that the `forEach()` higher order function is predefined JavaScript function. 126 | 127 | Here's an example of a user made higher order function: 128 | 129 | ``` 130 | function map(func, a) { 131 | const result = new Array(a.length); 132 | for (let i = 0; i < a.length; i++) { 133 | result[i] = func(a[i]); 134 | } 135 | return result; 136 | } 137 | 138 | const f = function (x) { 139 | return x * x * x; 140 | } 141 | 142 | const numbers = [0, 1, 2, 5, 10]; 143 | const cube = map(f, numbers); 144 | console.log(cube); 145 | ``` 146 |
147 |
-------------------------------------------------------------------------------- /Basic Javascript/03.Functions/ArrowFunctions.md: -------------------------------------------------------------------------------- 1 | # Arrow Functions In Javascript 2 | 3 | ## What are Arrow Functions? 4 | An arrow function expression is a compact alternative to a traditional function expression, but is limited and can't be used in all situations. 5 | 6 | Arrow functions were introduced in ES6. 7 | 8 | ``` 9 | let myFunction = (a, b) => a * b; 10 | ``` 11 | 12 | There are differences between arrow functions and traditional functions, as well as some limitations: 13 | 14 | - Arrow functions don't have their own bindings to `this`, `arguments` or `super`, and should not be used as methods. 15 | - Arrow functions don't have access to the `new.target` keyword. 16 | - Arrow functions aren't suitable for `call`, `apply` and `bind` methods, which generally rely on establishing a scope. 17 | - Arrow functions cannot be used as `constructors`. 18 | - Arrow functions cannot use `yield`, within its body. 19 | 20 | A more comprehensive example of arrow function: 21 | 22 | ``` 23 | const materials = [ 24 | 'Hydrogen', 25 | 'Helium', 26 | 'Lithium', 27 | 'Beryllium' 28 | ]; 29 | 30 | console.log(materials.map(material => material.length)); 31 | // expected output: Array [8, 6, 7, 9] 32 | ``` 33 |
34 | 35 | ## Converting a "traditional anonymous function" to the simplest "arrow function": 36 | 37 | ``` 38 | // Traditional Anonymous Function 39 | (function (a) { 40 | return a + 100; 41 | }); 42 | 43 | // Arrow Function Break Down 44 | 45 | // 1. Remove the word "function" and place arrow between the argument and opening body bracket 46 | (a) => { 47 | return a + 100; 48 | }; 49 | 50 | // 2. Remove the body braces and word "return" — the return is implied. 51 | (a) => a + 100; 52 | 53 | // 3. Remove the argument parentheses 54 | a => a + 100; 55 | 56 | ``` 57 | 58 | ## **Basic Syntax** 59 | 60 | One param. With simple expression return is not needed: 61 | ``` 62 | param => expression 63 | (param) => expression 64 | ``` 65 | 66 | Multiple params require parentheses. With simple expression return is not needed: 67 | 68 | ``` 69 | (param1, paramN) => expression 70 | ``` 71 | Multiline statements require body braces and return: 72 | 73 | ``` 74 | // The parentheses are optional with one single parameter 75 | param => { 76 | const a = 1; 77 | return a + param; 78 | } 79 | ``` 80 | 81 |
82 |
-------------------------------------------------------------------------------- /Basic Javascript/03.Functions/Parameters_Arguments.md: -------------------------------------------------------------------------------- 1 | # Parameters In Javascript 2 | 3 | Functions Parameters
4 | Function parameters are the names listed in the function definition. 5 | 6 | ``` 7 | function name(parameter1, parameter2, parameter3) { // any number of parameters 8 | 9 | // code to be executed 10 | 11 | } 12 | ``` 13 | Here `parameter1`, `parameter2`, `parameter3` are all function parameters 14 | 15 | 16 | Functions Arguments
17 | Function arguments are the real values passed to (and received by) the function. 18 | 19 |
20 | 21 | Default Parameters
22 | If a function is called with missing arguments (less than declared), the missing values are set to undefined. 23 | 24 | Furthermore we can ourselves assign a default value for the parameters of a function. 25 | ``` 26 | // ES5 Method 27 | 28 | function areaOfRectangle(length, breadth) { 29 | if(breadth === undefined) { // ( = = = ) 30 | breadth = 2; 31 | } 32 | return length * breadth; 33 | } 34 | ``` 35 |
36 | 37 | *ES6 (ES2015) allowed the assignment of default parameters in the **function declaration***. 38 | ``` 39 | function areaOfRectangle(length, breadth = 2) { 40 | return length * breadth; 41 | } 42 | ``` 43 | 44 | ## Arguments Object *(Slightly Advanced)* 45 | The arguments object are inbuilt object in JavaScript functions. 46 | The argument object contains an array of the arguments used when the function is called (invoked). 47 | 48 | ``` 49 | x = sumOfNumbers(1, 123, 500, 115, 44, 88); 50 | 51 | function sumOfNumbers() { 52 | let sum = 0; 53 | for (let i = 0; i < arguments.length; i++) { 54 | sum += arguments[i]; 55 | } 56 | return sum; 57 | } 58 | 59 | ``` 60 | 61 | ## Arguments Passed by Value 62 | In a function call the parameters are called as arguments. The pass by value sends the value of variable to the function. It does not sends the address of variable. If the function changes the value of arguments then it does not affect the original value. 63 | 64 |
65 | 66 | ## Objects are Passed by Reference 67 | 68 | In JavaScript, object references are values. 69 | Because of this, objects will behave like they are passed by **reference**. 70 | If a function changes an object property, it changes the original value. 71 | 72 | ***Changes to object properties are visible (reflected) outside the function.*** 73 |
74 |
-------------------------------------------------------------------------------- /Basic Javascript/04.Hoisting/Hoisting.js: -------------------------------------------------------------------------------- 1 | // HOISTING IN JAVASCRIPT 2 | // --------------------------------------------------------------------------------- 3 | // Type - 1 HOISTING ( Value Hoisting) 4 | 5 | console.log(areaOfSquare(5)); 6 | 7 | function areaOfSquare(side) { 8 | return side * side; 9 | } 10 | var var1 = 10; 11 | 12 | // --------------------------------------------------------------------------------- 13 | // Type - 2 HOISTING ( Declaration Hoisting) 14 | 15 | console.log('var ->', side); 16 | 17 | var side = 10; 18 | 19 | console.log('var ->', side); 20 | 21 | // --------------------------------------------------------------------------------- 22 | // Type - 3 HOISTING 23 | 24 | console.log('let ->', variable1); 25 | console.log('const ->', constant1); 26 | 27 | let variable1 = 5; 28 | const constant1 = 10; 29 | 30 | console.log('let ->', variable1); 31 | console.log('const ->', constant1); 32 | -------------------------------------------------------------------------------- /Basic Javascript/04.Hoisting/Hoisting.md: -------------------------------------------------------------------------------- 1 | # Hoisting in Javascript 2 | 3 | JavaScript **Hoisting** refers to the process whereby the interpreter appears to move the ***declaration*** of functions, variables or classes to the top of their scope, prior to execution of the code. 4 | ## Types of Hoisting 5 | any of the following behaviors may be regarded as hoisting: 6 | 7 | - Being able to use a variable's value in its scope before the line it is declared. ("Value hoisting") 8 | - Being able to reference a variable in its scope before the line it is declared, without throwing a ReferenceError, but the value is always undefined. ("Declaration hoisting") 9 | - The declaration of the variable causes behavior changes in its scope before the line in which it is declared. 10 | 11 | The four function declaration `(function, function*, async function, and async function*)` are hoisted with type 1 behavior; `var` declaration is hoisted with type 2 behavior; `let`, `const`, and `class` declarations (also collectively called lexical declarations) are hoisted with type 3 behavior. 12 | 13 | Some prefer to see `let`, `const`, and `class` as **non-hoisting**, because the temporal dead zone strictly forbids any use of the variable before its declaration. 14 | 15 |
16 | 17 | **Temporal Dead Zone** - ***A let or const variable is said to be in a "temporal dead zone" (TDZ) from the start of the block until code execution reaches the line where the variable is declared and initialized.*** 18 | 19 | While inside the TDZ, the variable has not been initialized with a value, and any attempt to access it will result in a `ReferenceError`. 20 | 21 | The variable is initialized with a value when execution reaches the line of code where it was declared 22 | 23 | ``` 24 | { // TDZ starts at beginning of scope 25 | console.log(bar); // undefined 26 | console.log(foo); // ReferenceError 27 | var bar = 1; 28 | let foo = 2; // End of TDZ (for foo) 29 | } 30 | 31 | ``` 32 |
33 | 34 | The term "temporal" is used because the zone depends on the order of execution (time) rather than the order in which the code is written (position). For example, the code below works because, even though the function that uses the `let` variable appears before the variable is declared, the function is *called outside the TDZ*. 35 | 36 | ``` 37 | { 38 | // TDZ starts at beginning of scope 39 | const func = () => console.log(letVar); // OK 40 | 41 | // Within the TDZ letVar access throws `ReferenceError` 42 | 43 | let letVar = 3; // End of TDZ (for letVar) 44 | func(); // Called outside TDZ! 45 | } 46 | 47 | ``` 48 |
49 |
-------------------------------------------------------------------------------- /Basic Javascript/04.Loops.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsc-tiu/JavascriptBootCamp/702686b9208ab9cad00ba19c99f57909f095950c/Basic Javascript/04.Loops.js -------------------------------------------------------------------------------- /Basic Javascript/05.Arrays.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsc-tiu/JavascriptBootCamp/702686b9208ab9cad00ba19c99f57909f095950c/Basic Javascript/05.Arrays.js -------------------------------------------------------------------------------- /Basic Javascript/06.Objects.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsc-tiu/JavascriptBootCamp/702686b9208ab9cad00ba19c99f57909f095950c/Basic Javascript/06.Objects.js -------------------------------------------------------------------------------- /Basic Javascript/07.EventLoop.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsc-tiu/JavascriptBootCamp/702686b9208ab9cad00ba19c99f57909f095950c/Basic Javascript/07.EventLoop.js -------------------------------------------------------------------------------- /Basic Javascript/08.DOM.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsc-tiu/JavascriptBootCamp/702686b9208ab9cad00ba19c99f57909f095950c/Basic Javascript/08.DOM.js -------------------------------------------------------------------------------- /Basic Javascript/Javascript Bootcamp Day 5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsc-tiu/JavascriptBootCamp/702686b9208ab9cad00ba19c99f57909f095950c/Basic Javascript/Javascript Bootcamp Day 5.pdf -------------------------------------------------------------------------------- /Basic Javascript/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Google Apps Script/DocumentApp.md: -------------------------------------------------------------------------------- 1 | # Google Docs [DocumentApp] 2 | ## Open Documents 3 | 4 | - ```DocumentApp``` is used to access and modify documents, something that can't be done with ```DriveApp```.
5 | 6 | - For example, we can insert and edit text inside a document using DocumentApp.
7 | 8 | - ```DocumentApp.openById()``` is used to get a document file in Google Docs. The syntax is similar to ```DriveApp.getFileById()```
9 | 10 | ###
Code Example: 11 | ```JavaScript 12 | let id = '1VFYfiTWVTahG9G8xG9G8x2a76ejv1fiTWVTahsAM'; 13 | 14 | let doc = DocumentApp.openById(id); 15 | let docName = doc.getName(); 16 | console.log(docName); 17 | ``` 18 | - This code snippet gets the document by its unique file id and then prints the document name fetched with ```getName()``` and stored in the variable ```docName```. 19 | 20 | ### Note: 21 | - DriveApp.getFileById() returns a file from Google Drive. 22 | 23 | - DocumentApp.openById() returns a document from Google Docs. 24 | 25 | - getId() is a function that returns the id of the file or document it is called on.
26 | 27 | --- 28 | 29 | ## Get File Contents 30 | - The ```getText()``` method returns the contents of the document. 31 | 32 | ###
Code Example: 33 | 34 | ```JavaScript 35 | let id = "1x1Ky-x1Kyejv1fiTejv1fiTWVTahG9GMgmAM"; 36 | 37 | let doc = DocumentApp.openById(id); 38 | let text = doc1.getText(); 39 | console.log(text); 40 | ``` 41 | - In this code snippet we open the document and get its text content using ```getText()``` and then print its contents out. 42 | 43 | --- 44 | 45 | ## Replace Text 46 | - The ```replaceText()``` method is used to edit and modify the document.
47 | 48 | - It takes 2 arguments: 49 | 1. A string to be replaced 50 | 2. A new string to replace it with
51 |
52 | - Every occurrence of the string to replace is replaced with the new string. 53 | 54 | ###
Code Example: 55 | 56 | ```JavaScript 57 | let id = '1x1Ky-x1Kyejv1fiTejv1fiTWVTahG9GMgmAM'; 58 | 59 | let doc = DocumentApp.openById(id); 60 | let oldText = doc.getText(); 61 | console.log(oldText); 62 | 63 | doc.replaceText('brilliant', 'exceptional'); 64 | let newText = doc.getText(); 65 | console.log(newText); 66 | ``` 67 | - In this code snippet we are replacing every occurence of the word "brilliant" with "exceptional" using the ```replaceText()``` method. 68 | --- 69 | 70 | ## Example Exercise: 71 | ```JavaScript 72 | let doc = DocumentApp.openById('226uAXY0YRUjHMW5LQqmJTpnzRkGmFLch0'); 73 | let replacements = [ 74 | ['Dog', 'Cat'], 75 | ['dog food', 'cat food'], 76 | ['chicken bones and mutton', 'fish bones and salmon'] 77 | ]; 78 | 79 | for (let replacement of replacements) { 80 | doc.replaceText(replacement[0],replacement[1]); 81 | } 82 | ``` 83 | - In this code snippet we make multiple replacements in the document.
84 | 85 | - If you look closely, you will notice we want to convert a document on dogs to a document on cats.
86 | 87 | - The ```replacements``` array consists of 3 arrays, that contain 2 strings each. 88 | + The first string is the text to be replaced. 89 | + The second string is new text to replace it with.
90 |
91 | 92 | - Inside the for...of loop we are making the replacements in the document as per each array defined above.
93 | --- 94 | ## We will be applying the skills learnt here in the Sum-Up Module. 95 | -------------------------------------------------------------------------------- /Google Apps Script/DriveApp.md: -------------------------------------------------------------------------------- 1 | # Google Drive [DriveApp] 2 | ## Get Files 3 | - Every file in Google Drive has a unique id.
4 | - The id will be a string of characters and numbers something like: 'e514a7d3e2061ca9e3'
5 | 6 | - ```DriveApp.getFileById()``` takes an id as a parameter and returns the matching file.
7 | 8 | - The ```getName()``` is a method that returns the file name. 9 | 10 | ### Note: 11 | - The ID of a file can be found by navigating to the Google Drive web-app. 12 | - Right Click on the file and click on "get sharable link" . 13 | - The File ID is the last part of that link, after id= .
14 | 15 | 16 | ###
Code Example: 17 | 18 | ```JavaScript 19 | let id = 'ac7d3e20622af72303e7bcd67a8e953189205bb6728a'; 20 | let file = DriveApp.getFileById(id); 21 | let fileName = file.getName(); 22 | 23 | console.log(fileName); 24 | ``` 25 | - This code snippet outputs the file name whose id is stored in the variable ```id```.
26 | 27 | - Then fetches the matching file and returns it to the file object.
28 | 29 | - Then we use the .getName() method on the file object to retrieve the file name.
30 | 31 | --- 32 | 33 | ## Rename Files 34 | 35 | - The ```setName()``` method sets the file name. 36 | 37 | ###
Code Example: 38 | 39 | ```JavaScript 40 | let id = 'ac7d3e20622af72303e7bcd67a8e953189205bb6728a'; 41 | let file = DriveApp.getFileById(id); 42 | 43 | let oldFileName = file.getName(); 44 | console.log(oldFileName); 45 | 46 | file.setName('Renamed File'); 47 | 48 | let newName = file.getName(); 49 | console.log(newName); 50 | ``` 51 | - This code snippet first prints the old file name.
52 | 53 | - Renames the file.
54 | - Then prints the new file name "Renamed File".
55 | 56 | --- 57 | 58 | ## Copy Files 59 | 60 | - The ```makeCopy()``` method creates a copy of a file.
61 | 62 | - It returns a new file which has the same contents as the original file but has a different file id.
63 | 64 | - The ```getId()``` method gets the id of a file.
65 | 66 | ###
Code Example: 67 | 68 | ```JavaScript 69 | let id = '1gJAiEKJd8NMdjI_EcI12y3iIYk3E8wokAJEOijsZcf0'; 70 | let file = DriveApp.getFileById(id); 71 | 72 | let firstCopy = file.makeCopy(); 73 | let firstCopyId = firstCopy.getId(); 74 | console.log(firstCopyId); 75 | 76 | let secondCopy = file.makeCopy(); 77 | let secondCopyId = secondCopy.getId(); 78 | console.log(secondCopyId); 79 | ``` 80 | - This code snippet makes a copy of the original file and then prints its id.
81 | 82 | - Then makes a second copy of the file and also prints its id.
83 | 84 | - This demonstrates how different copies of the same file can be made, and also that they have different file ids but the same file content.
85 | 86 | ### Note: 87 | - makeCopy() can take a single argument which is the name of the copy of the file. 88 | ```JavaScript 89 | let secondCopy = file.makeCopy("GDSC"); 90 | ``` 91 | - This code snippet will rename the second copy of the file object and save it as "GDSC" instead of some default file name. 92 | --- 93 | ## We will be applying the skills learnt here in the Sum-Up Module. 94 | -------------------------------------------------------------------------------- /Google Apps Script/Intro.md: -------------------------------------------------------------------------------- 1 | # What is Apps Script Used For? 2 | 3 | - Apps Script was initially released by Google back in August, 2009.
4 | 5 | - It lets you use code to manipulate, customize and automate Google Applications like Drive, Docs and Sheets among others.
6 | 7 | - Apps Script uses JavaScript, so your existing knowledge of JavaScript will work with Apps Script as well.
8 | 9 | - Apps Script also uses its own functions that help you connect to Google Applications.
10 | 11 | - We use the Apps Script Tool to deploy our code. The Dashboard can be found at [script.google.com](script.google.com) 12 | 13 | -------------------------------------------------------------------------------- /Google Apps Script/SpreadsheetApp.md: -------------------------------------------------------------------------------- 1 | # Google Drive [SpreadsheetApp] 2 | ## Open Spreadsheets 3 | - Similar to the DocumentApp, we can use ```SpreadsheetApp.openById()``` in the SpreadsheetApp to open a spreadsheet. 4 | - The function call takes the file id as an argument. 5 | 6 | --- 7 | ## Printing Cell Values 8 | - The ```getRange().getValues()``` syntax is used to print cell values.
9 | 10 | - The ```getRange()``` method takes the table range and the ```getValues()``` method returns the values in that range as a nested array.
11 | 12 |
13 | ###
Code Example: 14 | 15 | ```JavaScript 16 | let id = '1QE4Zf1b_Sw7sss8efMoHKGOEFCk2J2pZHyXGT_nPueo'; 17 | let sheet = SpreadsheetApp.openById(id); 18 | 19 | let values = sheet.getRange("A3:C9").getValues(); 20 | 21 | console.log(values[0][0]) 22 | ``` 23 | - The code snippet above prints the value at cell A3. Since this is a nested array, the indexing [0] [0] returns the first element in the array of values returned. 24 | --- 25 | 26 | ## Example Exercise 1: 27 | - Suppose we have a table with 2 columns A and B, and 6 rows. 28 | - If we want to print all the values of column A first and then all the values of column B, we will use the following code snippet. 29 | 30 | ###
Code Example: 31 | ```JavaScript 32 | let id = '1QE4pZs8efMoHKGOEHyXGT_nPZf1b_Sw7ssFCk2J2ueo'; 33 | let sheet = SpreadsheetApp.openById(id); 34 | 35 | let columnA = sheet.getRange('A1:A6').getValues(); 36 | let columnB = sheet.getRange('B1:B6').getValues(); 37 | 38 | for (let row of columnA) { 39 | for (let value of row) { 40 | console.log(value); 41 | } 42 | } 43 | 44 | for(let row of columnB){ 45 | for(let value of row){ 46 | console.log(value) 47 | } 48 | } 49 | ``` 50 | - In this code snippet, we read the spreadsheet into the sheet variable.
51 | 52 | - Then we get the values of column A into the variable columnA and we do the same for column B.
53 | 54 | - Then we traverse the Nested Array returned for column A and print all its values and then we do the same for column B.
55 | 56 | - The output of the code is all the values of column A are printed first, then all the values of column B are printed. 57 | --- 58 | 59 | ## Example Exercise 2: 60 | Suppose we have the following table 61 | 62 | | | A | B | 63 | |---|----------|----------| 64 | | 1 | CUSTOMER | CURRENCY | 65 | | 2 | Bob | USD | 66 | | 3 | Jay | INR | 67 | | 4 | Vikram | INR | 68 | | 5 | Akhil | GBP | 69 | | 6 | Raj | USD | 70 | | 7 | Manisha | GBP | 71 | | 8 | Priyanka | GBP | 72 | | 9 | Alisha | GBP | 73 | 74 | - Here the column name A and B are used by Sheets to index columns. It is not a part of the table data.
75 | 76 | - The sl. nos. 1-9 are used by Sheets to index rows. It is not a part of the table data.
77 | 78 | - Question: Find out how many customers are paying with INR. 79 | 80 | ###
Code Example: 81 | 82 | ```JavaScript 83 | let id = 'oHnPZf1b_Sw7ssFCk2KGOEHyXGT_1QE4pZs8efMJ2ueo'; 84 | let sheet = SpreadsheetApp.openById(id); 85 | 86 | let vals = sheet.getRange('B1:B8').getValues(); 87 | let rupeeCount = 0; 88 | for (let row of vals) { 89 | for (let cell of row) { 90 | if(cell === 'INR'){ 91 | rupeeCount++; 92 | } 93 | } 94 | } 95 | console.log(rupeeCount + ' customers are paying with INR.'); 96 | ``` 97 | 98 | Output:    2 customers are paying with INR. 99 | 100 | --- 101 | ## We will be applying the skills learnt here in the Sum-Up Module. -------------------------------------------------------------------------------- /Google Apps Script/Sum-Up.md: -------------------------------------------------------------------------------- 1 | # Sum-Up 2 | ## Summary 3 | - In this section we will try to use all our knowledge of manipulating files in the Google Drive, Docs and Sheets to automate a task.
4 | 5 | - We will try to automate the task of creating wedding invitation cards but this can be used for other purposes as well.
6 | 7 | - If you think about it, you will come to realize that a wedding invitation card is essentially the same for everyone except the Name of the person and a few other key details. 8 | 9 | - The intuition is to create the first card and then follow it like a template to create all the other cards until you are done creating all the cards necessary. 10 | 11 | - We will use DriveApp, DocumentApp, and SpreadsheetApp to automate this process. 12 | --- 13 | 14 |
15 |

Requirements

16 | The program to automate our task, will need 2 files in order to work as expected. 17 | 18 | 1.   An invitation card document in Docs, where each key term is placeholder text. 19 | 20 | - For example: 21 | 22 | - ```We cordially invite TITLE GUEST to our daughter's wedding. Being her RELATIONSHIP, your presence is highly appreciated.``` 23 | 24 |
25 | 26 | 2.   A spreadsheet in Sheets, that stores the values of the key terms for every invitation card. 27 | 28 | - For example: 29 | 30 | | | A | B | C | 31 | |---|----------|-------|---------------| 32 | | 1 | GUEST | TITLE | RELATIONSHIP | 33 | | 2 | Bob | Mr. | Brother | 34 | | 3 | Maya | Mrs. | Sister-in-Law | 35 | | 4 | Rajiv | Mr. | Friend | 36 | | 5 | Anika | Ms. | Friend | 37 | | 6 | Vikram | Mr. | Colleague | 38 | | 7 | Anish | Mr. | Father-in-law | 39 | | 8 | Priyanka | Ms. | Cousin | 40 | | 9 | Alisha | Mrs. | Cousin | 41 | 42 |
43 |
44 | 45 | 46 | 47 | [comment]: <> (STEP 1) 48 | 49 |
50 |

Step 1: Create a Copy of the File

51 | 52 | ```javascript 53 | let fileId = '226uAXY0YRUj-HMW5LQZ2YeeJgyDqmJTpnzRkGmFLch0'; 54 | 55 | function makeCopy(id, name) { 56 | let file = DriveApp.getFileById(id); 57 | let copy = file.makeCopy(name); 58 | return copy.getId(); 59 | } 60 | 61 | console.log(makeCopy(fileId, 'Copy of the invitation card template')); 62 | ``` 63 |
73 | 74 | 75 | 76 | [comment]: <> (STEP 2) 77 | 78 |
79 |

Step 2: Update Document

80 | 81 | ```javascript 82 | import { fileCopy, Edits } from ; 83 | 84 | function updateDoc(doc, edits) { 85 | 86 | for(let edit of edits){ 87 | doc.replaceText(edit[0], edit[1]) 88 | } 89 | } 90 | 91 | updateDoc(fileCopy, Edits); 92 | ``` 93 |
    94 |
  • This function replaces text in a document copied from a invitation card template.

  • 95 | 96 |
  • We will use this function later.

  • 97 | 98 |
99 | 100 | 101 | 102 | [comment]: <> (STEP 3) 103 | 104 |
105 |

Step 3: Get The Actual Values From The Spreadsheet

106 | 107 | ```javascript 108 | let spreadsheetId = '114hEvWFEbgwmk9TIF54m6bRM6Nb-anMXF4G4qN1cufY'; 109 | 110 | function makeCopy(id, name) { 111 | let file = DriveApp.getFileById(id); 112 | let copy = file.makeCopy(name); 113 | return copy.getId(); 114 | } 115 | 116 | function updateDoc(doc, edits) { 117 | for (let edit of edits) { 118 | doc.replaceText(edit[0], edit[1]); 119 | } 120 | } 121 | 122 | function main() { 123 | let sheet = SpreadsheetApp.openById(spreadsheetId); 124 | let values = sheet.getRange('A2:C5').getValues(); 125 | console.log(values[0][0]) 126 | } 127 | 128 | main(); 129 | ``` 130 | 131 |
138 | 139 | 140 | 141 | [comment]: <> (STEP 4) 142 |
143 |

Step 4: Make Multiple Copies Of the File

144 | 145 | ```javascript 146 | let spreadsheetId = '114hEvWFEbgwmk9TIF54m6bRM6Nb-anMXF4G4qN1cufY'; 147 | let contractId = '226uAXY0YRUj-HMW5LQZ2YeeJgyDqmJTpnzRkGmFLch0'; 148 | 149 | 150 | function makeCopy(id, name) { 151 | let file = DriveApp.getFileById(id); 152 | let copy = file.makeCopy(name); 153 | return copy.getId(); 154 | } 155 | 156 | function updateDoc(doc, edits) { 157 | for (let edit of edits) { 158 | doc.replaceText(edit[0], edit[1]); 159 | } 160 | } 161 | 162 | function main() { 163 | let sheet = SpreadsheetApp.openById(spreadsheetId); 164 | let values = sheet.getRange("A2:C5").getValues(); 165 | 166 | for(let row of values){ 167 | let copyId = makeCopy(contractId, row[0] + 'Contract'); 168 | console.log(row, ' ', copyId); 169 | } 170 | } 171 | 172 | main(); 173 | ``` 174 | 175 |
180 | 181 | 182 | 183 | [comment]: <> (STEP 5) 184 | 185 |
186 |

Step 5: Create a Copy

187 | 188 | ```javascript 189 | let spreadsheetId = '114hEvWFEbgwmk9TIF54m6bRM6Nb-anMXF4G4qN1cufY'; 190 | let contractId = '226uAXY0YRUj-HMW5LQZ2YeeJgyDqmJTpnzRkGmFLch0'; 191 | 192 | 193 | function makeCopy(id, name) { 194 | let file = DriveApp.getFileById(id); 195 | let copy = file.makeCopy(name); 196 | return copy.getId(); 197 | } 198 | 199 | function updateDoc(doc, edits) { 200 | for (let edit of edits) { 201 | doc.replaceText(edit[0], edit[1]); 202 | } 203 | } 204 | 205 | function main() { 206 | let sheet = SpreadsheetApp.openById(spreadsheetId); 207 | let values = sheet.getRange("A2:C5").getValues(); 208 | 209 | for (let row of values) { 210 | let copyId = makeCopy(contractId, row[0] + ' Contract'); 211 | let copy = DocumentApp.openById(copyId); 212 | let edits = [ 213 | 214 | ['GUEST', row[0]], 215 | ['TITLE', row[1]], 216 | ['RELATIONSHIP', row[2]] 217 | ] 218 | updateDoc(copy, edits); 219 | } 220 | } 221 | 222 | main(); 223 | ``` 224 |
230 | 231 | ## Congratulations!! 232 | ### You just learnt how to apply Apps Script to Automate a tedious task of creating the writeups for a Wedding Invitation Card using DriveApp, DocumentApp and SpreadsheetApp. 233 | -------------------------------------------------------------------------------- /How Javascript Works/How JavaScript Works.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsc-tiu/JavascriptBootCamp/702686b9208ab9cad00ba19c99f57909f095950c/How Javascript Works/How JavaScript Works.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JAVASCRIPT BOOTCAMP 2 | This repository is exclusive to javascript bootcamp, organized at GDSC TIU. 3 | #### An introductory resource by [Gourav Ghosal](https://github.com/gourav221b), Chapter Lead, Google Developer Students Club, Techno India University. 4 | 5 | ## Table of Contents 6 | --- 7 | ### 1. Basic Javascript 8 |
9 | 10 | - [A long long time ago.....](Basic%20Javascript/01.DataType/LongTimeAgo.md) 11 | 12 | - [Data Types](Basic%20Javascript/01.DataType/01.DataType.md) 13 | - [Variables](Basic%20Javascript/02.Variables/02.Variables.md) 14 | - [Functions](Basic%20Javascript/03.Functions/03.Functions.md) 15 | 16 | - Loops 17 | - Arrays 18 | - Objects 19 | - DOM Manipulation 20 | 21 |
22 | 23 | --- 24 | 25 | ### 2. How Javascript Works 26 |
27 | 28 | - [Javascript Engine](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 29 | 30 | - [Execution Contexts](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 31 | - [Global Execution Context](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 32 | - [Function Execution Context](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 33 | - [Creation Phase](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 34 | - The Variable Object 35 | - [Hoisting](Basic%20Javascript/04.Hoisting/Hoisting.md) 36 | - Scope Chan 37 | - *this* Keyword 38 | - [Execution Phase](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 39 | - [Execution Stack](How%20Javascript%20Works\How%20JavaScript%20Works.pdf) 40 | - Event Loops 41 | 42 |
43 | 44 | --- 45 | 46 |
47 | 48 | ### 3. Advanced Javascript 49 |
50 | 51 | - Promises and Callbacks 52 | 53 | - Closures 54 | - Async and Await 55 | - OOPS 56 | - Modules 57 | - Intro to React Js 58 |
59 | 60 | --- 61 | 62 |
63 | 64 | 65 | ### 4. Google Apps Script 66 |
67 | 68 | - [What is Apps Script?](Google%20Apps%20Script/Intro.md) 69 | - [Google Drive](Google%20Apps%20Script/DriveApp.md) 70 | - [Google Docs](Google%20Apps%20Script/DocumentApp.md) 71 | - [Google Sheets](Google%20Apps%20Script/SpreadsheetApp.md) 72 | - [Sum-Up](Google%20Apps%20Script/Sum-Up.md) 73 | 74 |
75 | 76 | --- 77 | 78 | --------------------------------------------------------------------------------