{"id":21696304,"url":"https://github.com/dinanathsj29/javascript-beginners-tutorial","last_synced_at":"2025-03-20T14:47:27.782Z","repository":{"id":49794340,"uuid":"172641046","full_name":"dinanathsj29/javascript-beginners-tutorial","owner":"dinanathsj29","description":"A JavaScript tutorials for beginners, An introduction to JavaScript programming languages building blocks, step-by-step guide to JavaScript","archived":false,"fork":false,"pushed_at":"2020-05-25T10:05:55.000Z","size":1780,"stargazers_count":167,"open_issues_count":1,"forks_count":68,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-25T14:11:21.651Z","etag":null,"topics":["arrays","conditions","dom-document-object-model","events","front-end-development","javascript-basic-programming","javascript-language-fundamentals","javascript-library","javascript-programming-language","javascript-programs","javascript-tutorial","javascript-typescript-es6","learning-javascript","loops","objects","plain-javascript","vanilla-javascript","variables-var-let-conts","webdevelopment","webprogramming"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dinanathsj29.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-26T05:00:22.000Z","updated_at":"2025-01-11T10:43:54.000Z","dependencies_parsed_at":"2022-09-24T04:31:31.554Z","dependency_job_id":null,"html_url":"https://github.com/dinanathsj29/javascript-beginners-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinanathsj29%2Fjavascript-beginners-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinanathsj29%2Fjavascript-beginners-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinanathsj29%2Fjavascript-beginners-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinanathsj29%2Fjavascript-beginners-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dinanathsj29","download_url":"https://codeload.github.com/dinanathsj29/javascript-beginners-tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244635919,"owners_count":20485440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arrays","conditions","dom-document-object-model","events","front-end-development","javascript-basic-programming","javascript-language-fundamentals","javascript-library","javascript-programming-language","javascript-programs","javascript-tutorial","javascript-typescript-es6","learning-javascript","loops","objects","plain-javascript","vanilla-javascript","variables-var-let-conts","webdevelopment","webprogramming"],"created_at":"2024-11-25T19:19:23.445Z","updated_at":"2025-03-20T14:47:27.762Z","avatar_url":"https://github.com/dinanathsj29.png","language":"HTML","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"_examples_javascript_beginners/assets/images/javascript_logo_4.png\" alt=\"JavaScript logo\" title=\"JavaScript for beginners\" width=\"200\" /\u003e\n\u003c/p\u003e\n    \nJavaScript for Beginners\n=====================\nJavaScript tutorial for Beginners\n=====================\nJavaScript basics and fundamentals for all\n=====================\n\nDescription\n---------------------\n\nJavaScript is a `scripting language of the web` that allows you to do/add Interactivity with User-Events, implement Conditions and Validations, Dynamic updates in a Web Page, etc.. In this practical course will learn JavaScript basics-programming fundamentals from scratch. We Will start with what is JavaScript? its uses, history, how to write JavaScript, etc. It will also cover various programming building blocks like variable, functions, array, conditionals, objects, and many more.\n\nTopics (separate with spaces)\n---------------------\n\nAdd topics to categorize your repository and make it more discoverable: \n\n- javascript-programming-language\n- javascript-language-fundamentals\n- javascript-basic-programming\n- javascript-tutorial\n- javascript-library\n- learning-javascript\n- javascript-programs\n- variables-var-let-const\n- conditions\n- loops\n- arrays\n- objects\n- events\n- dom-document-object-model\n- webdevelopment\n- front-end-development\n- webprogramming\n- plain-javascript\n- vanilla-javascript\n- javascript-typescript-es6\n\nPrerequisites for current course / What you need to know\n---------------------\n\nTo move forward with JavaScript you just need basic knowledge of XHTML/HTML. Here, you will learn how easy it is to add interactivity to a web page using JavaScript. But, before we begin, make sure that you have some working knowledge and/or general understanding of:\n- The Internet and the World Wide Web (WWW) [Web Design Development Foundations-Web Technology Fundamentals](https://github.com/dinanathsj29/web-design-development-fundamentals)\n- Good working knowledge of HyperText Markup Language (HTML) [HTML5 Essentials](https://github.com/dinanathsj29/html5-essentials) and \n- Its good to know [CSS3 Fundamentals](https://github.com/dinanathsj29/css3-fundamentals)\n\nTopics include\n=====================\n\n1. [Course Introduction](#section-01-course-introduction)\n    - 01.01. [Welcome](#0101-welcome)\n    - 01.02. [Who is this for? Audience](#0102-who-is-this-for-audience)\n2. [Introducing JavaScript](#section-02-introducing-javascript)\n    - 02.01. [Importance](#0201-importance)\n    - 02.02. [What is JavaScript?](#0202-what-is-javascript)\n    - 02.03. [What is a scripting language?](#0203-what-is-a-scripting-language)\n    - 02.04. [What can you do with JavaScript?](#0204-what-can-you-do-with-javascript) | [Use of JavaScript?](#0204-use-of-javascript)\n    - 02.05. [Where does the JavaScript code run?](#0205-where-does-the-javascript-code-run)\n    - 02.06. [Who are using JavaScript?](#0206-who-are-using-javascript)\n    - 02.07. [History of JavaScript](#0207-history-of-javascript)\n    - 02.08. [JavaScript Vs ECMAScript](#0208-javascript-vs-ecmascript)\n    - 02.09. [Types of Script](#0209-types-of-script) | [Various Scripting languages](#0209-various-scripting-languages) | [Client-Side Scripting Vs Server Side Scripting](#0209-client-side-scripting-vs-server-side-scripting)\n    - 02.10. [Prerequisites of using HTML and JavaScript](#0210-prerequisites-of-using-html-and-javascript)\n3. [JavaScript Getting Started](#section-03-javascript-getting-started)\n    - 03.01. [How to write Javascript?](#0301-how-to-write-javascript) | [JavaScript in HTML](#0301-javascript-in-html)\n    - 03.02. [Where to write JavaScript in HTML?](#0302-where-to-write-javascript-in-html) | [Where to embed include write put JavaScript in HTML?](#0302-where-to-embed-include-write-put-javascript-in-html)\n    - 03.03. [JavaScript Code structure](#0303-javascript-code-structure)\n    - 03.04. [JavaScript Keywords](#0304-javascript-keywords)\n    - 03.05. [Comments](#0305-Comments)\n4. [JavaScript Language Fundamentals](#section-04-javascript-language-fundamentals)\n    - 04.01. [Generating Output](#0401-generating-output)\n5. [Variables](#section-05-variables)\n    - 05.01. [What is Variable?](#0501-what-is-variable)\n    - 05.02. [Declaring variable without a value](#0502-declaring-variable-without-a-value) | [Creating a variable without a value](#0502-Creating-a-variable-without-a-value)\n    - 05.03. [Declaring multiple variables at once](#0503-declaring-multiple-variables-at-once)\n    - 05.04. [Variable Naming Conventions](#0504-variable-naming-conventions) | [Variable Naming Conventions (Identifiers)](#0504-variable-naming-conventions-identifiers)\n    - 05.05. [Variable Scope](#0505-variable-scope)\n    - 05.06. [The let and const keywords ES6](#0506-the-let-and-const-keywords-es6)\n6. [Data types](#section-06-data-types)\n    - 06.01. [Data types](#0601-data-types)\n    - 06.02. [Primitive data type](#0602-primitive-data-type) | [Primitive, Primary or Value data type](#0602-primitive-primary-or-value-data-type)\n    - 06.03. [Non-primitive data type](#0603-non-primitive-data-type) | [Non-primitive, Reference or Composite data type](#0603-non-primitive-reference-or-composite-data-type)\n    - 06.04. [JavaScript has Dynamic Types](#0604-javascript-has-dynamic-types)\n    - 06.05. [The typeof Operator](#0605-the-typeof-operator)\n    - 06.06. [Type conversion](#0606-type-conversion) | [typeof parseInt parseFloat](#0606-typeof-parseint-parsefloat)\n    - 06.07. [Type coercion](#0607-type-coercion)\n7. [Operators](#section-07-operators)\n    - 07.01. [What is the Operator?](#0701-what-is-the-operator)\n    - 07.02. [Arithmetic Operators](#0702-arithmetic-operators)\n    - 07.03. [Assignment Operators](#0703-assignment-operators)\n    - 07.04. [Logical Operators](#0704-logical-operators)\n    - 07.05. [Comparison Operators](#0705-comparison-operators) | [Relational Operators](#0705-relational-operators)\n    - 07.06. [Conditional Operator](#0706-conditional-perator) | [Ternary Operator](#0706-ternary-operator)\n    - 07.07. [String Operators](#0707-string-operators)\n    - 07.08. [Operator precedence](#0708-operator-precedence)\n8. [Functions](#section-08-functions)\n    - 08.01. [What is a Function?](#0801-what-is-a-function)\n    - 08.02. [Types of Function](#0802-types-of-function)\n    - 08.03. [Different ways to define Function](#0803-different-ways-to-define-function)\n    - 08.04. [String Methods and Concatenation](#0804-string-methods-and-concatenation)\n    - 08.05. [Template String](#0805-template-string) | [Template Literals](#0805-template-literals)\n9. [Loops](#section-09-loops) | [Loops and Iterations](#section-09-loops-and-iterations) \n    - 09.01. [The for loop](#0901-the-for-loop)\n    - 09.02. [The while loop](#0902-the-while-loop)\n    - 09.03. [The do while loop](#0903-the-do-while-loop)\n    - 09.04. [The for in loop](#0904-the-for-in-loop)\n    - 09.05. [The for of loop](#0905-the-for-of-loop)\n    - 09.06. [Break and Continue statement](#0906-break-and-continue-statement)\n    - 09.07. [for each loop](#0907-for-each-loop)\n10. [Conditions - Control Flow](#section-10-conditions)\n    - 10.01. [The if statement](#1001-the-if-statement) | [The if statement and comparison operators](#1001-the-if-statement-and-comparison-operators)\n    - 10.02. [The if else statement](#1002-the-if-else-statement)\n    - 10.03. [The if else if else statement](#1003-the-if-else-if-else-statement)\n    - 10.04. [The switch case statement](#1004-the-switch-case-statement)\n11. [Array](#section-11-array)\n    - 11.01. [What is an Array?](#1101-what-is-an-array)\n    - 11.02. [Create Array by array literal](#1102-create-array-by-array-literal)\n    - 11.03. [Create Array by creating an instance of array directly](#1103-create-array-by-creating-an-instance-of-array-directly)\n    - 11.04. [Create Array by using an array constructor](#1104-create-array-by-using-an-array-constructor)\n    - 11.05. [Getting the Length of an Array](#1105-getting-the-length-of-an-array)\n    - 11.06. [Accessing Looping through an Array Elements](#1106-accessing-looping-through-an-array-elements) | \n    [Loop through an Array Elements](#1106-loop-through-an-array-elements)\n    - 11.07. [Adding Editing an Array Elements](#1107-adding-editing-an-array-elements)\n    - 11.08. [Removing Deleting an Array Elements](#1108-removing-deleting-an-array-elements)\n    - 11.09. [Array properties and methods](#1109-array-properties-and-methods)\n12. [Objects](#section-12-objects)\n    - 12.01. [Real Life Objects](#1201-real-life-objects) | [Object Properties and Method examples](#1201-object-properties-and-method-examples)\n    - 12.02. [What is an Object?](#1202-what-is-an-object)\n    - 12.03. [Object literal](#1203-object-literal)\n    - 12.04. [Creating an instance of Object directly](#1204-creating-an-instance-of-object-directly)\n    - 12.05. [Object constructor](#1205-object-constructor)\n    - 12.06. [Accessing objects properties](#1206-accessing-objects-properties) | [Looping through Objects properties](#1206-looping-through-objects-properties)\n    - 12.07. [Removing Deleting objects properties](#1207-removing-deleting-objects-properties)\n    - 12.08. [Manipulating by Value Vs Reference](#1208-manipulating-by-value-vs-reference)\n    - 12.09. [The Window object](#1209-the-window-object)\n    - 12.10. [The Math Object](#1210-the-math-object)\n    - 12.11. [Date and Time](#1211-date-and-time)\n13. [Events](#section-13-events)\n    - 13.01. [Understanding Events and Event Handlers](#1301-understanding-events-and-event-handlers)\n    - 13.02. [Different Event category](#1302-different-event-category)\n    - 13.03. [Different ways to write the event handler](#1303-different-ways-to-write-the-event-handler)\n14. [DOM (Document Object Model)](#section-14-dom-document-object-model)\n    - 14.01. [What is DOM?](#1401-what-is-dom) | [What is the Document Object Model?](#1401-what-is-the-document-object-model)\n    - 14.02. [Node](#1402-node)\n    - 14.03. [JavaScript DOM Selectors](#1403-javascript-dom-selectors)\n    - 14.04. [JavaScript DOM CSS Styling](#1404-javascript-dom-css-styling)\n    - 14.05. [JavaScript DOM HTML get set attributes](#1405-javaScript-dom-html-get-set-attributes)\n15. [What's Next Step?](#section-15-whats-next-step)\n\nSection 01. Course Introduction\n=====================\n\n01.01. Welcome\n---------------------\n\nHi All, I'm **`Dinanath Jayaswal, Senior UI/Web Developer and Adobe Certified Expert Professional`**, I wanna welcome you to JavaScript for Beginners. In this course, I will take you through with the ins and outs of learning JavaScript. This course will help you to learn the fundamentals of programming with JavaScript scripting language, from the basics to advanced topics step-by-step.\n\n01.02. Who is this for? Audience\n---------------------\n\nThis course is for any Web Designer, Developer who is interested in dynamic Web Design and Development / Web Programming with JavaScript. Anyone who wants to make a career in Web Development or planning on being a front-end developer must learn JavaScript.\n\nSection 02. Introducing JavaScript\n=====================\n\n02.01. Importance\n---------------------\n\n### 3 pillars / core Languages/Technologies used for Front End Web Design/Development:\n\n1. **HTML (HyperText Markup Language)** - Markup language, Essential Page Structure/Content, Readable and convey structure to a user, Text Layout Model, page Mark-up, Text, Tags, Data, details for pages, Images, Tables, Anchor Links, Forms\n    - HTML is an acronym stands for `HyperText Markup Language` which is used for creating `web pages and web applications`\n    - HTML is not a programming language; it is a markup language that defines the structure of your content ie. document\n\n2. **CSS (Cascading Style Sheet)** - Style Sheet language, Page Design / Presentation / Layouts / Styling / Formattings, look and feel, Creative part of Web Pages\n    - CSS is a stylesheet language that allows you to control the appearance (look and feel) of your webpages\n\n3. **`JavaScript (JS) - Scripting language, Dynamic Page Behaviour, Logics, Conditions and Validations, Events (mouse click, hover), Interactivity with User, Dynamic updates in a Web Page`**\n    - JavaScript is a `scripting language of the web` that allows you to do Interactivity with User-Events, implement Conditions and Validations, Dynamic updates in a Web Page, etc.\n\n\u003e **Syntax \u0026 Example**: `02.01.js.intro.html`\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\n  \u003chead\u003e\n\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n    \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\"\u003e\n    \u003ctitle\u003e02.01.js.intro.html\u003c/title\u003e\n\n    \u003c!-- internal style --\u003e\n    \u003cstyle\u003e\n    /* css selector: { property:value; } */\n      body {\n          font-family: arial;\n      }\n    \u003c/style\u003e\n\n    \u003c!-- internal JavaScript - head section --\u003e\n    \u003cscript\u003e\n      // Write all JavaScript code here\n      alert('welcome to JavaScript');\n\n    \u003c/script\u003e\n  \n  \u003c/head\u003e\n\n  \u003cbody\u003e\n\n    Content\n\n    \u003c!-- internal JavaScript - body section --\u003e\n    \u003cscript\u003e\n        /* Write all JavaScript code here */\n        console.log('welcome to JavaScript');\n        \n    \u003c/script\u003e\n\n  \u003c/body\u003e\n\n\u003c/html\u003e\n```\n\n02.02. What is JavaScript?\n---------------------\n\n- JavaScript is `1 of the 3 core language/layers` of web...(HTML, CSS \u0026 JavaScript)\n- JavaScript is one of the most popular, widely used, lightweight scripting programming language\n- JavaScript is an `Open Source`, `Cross-Platform`, and `Browser-based Client-Side (user computer)` programming language of the web\n- JavaScript is a dynamic computer programming language. It is an `interpreted (translated)` programming language with `object-oriented capabilities`\n- JavaScript is officially maintained by `ECMA (European Computer Manufacturers Association) as ECMAScript`\n- ECMAScript 6 (or `ES6` or ECMAScript 2015) is the latest major version of the ECMAScript standard\n- JavaScript is case sensitive language\n\n\u003e **Note**: \u003cbr/\u003e\nNow-a-days with the help of `Node (Node.js)` JavaScript is used for `Back-end (Server-side)` API development. JavaScript is not compiled language, but it is a translated language (JavaScript Translator (embedded in the browser engine) is responsible for translating the JavaScript code for the web browser.\n\n\u003cp\u003e\n  \u003cfigure\u003e\n    \u0026nbsp;\u0026nbsp;\u0026nbsp; \u003cimg src=\"./_examples_javascript_beginners/assets/images/2.2.1-stackoverflow-developer-survey-2019.png\" alt=\"Stackoverflow Programming, Scripting, and Markup Languages Survey 2019\" title=\"Stackoverflow Programming, Scripting, and Markup Languages Survey 2019\" width=\"1000\" border=\"2\" /\u003e\n    \u003cfigcaption\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; Image 02.02.01 - Stackoverflow Programming, Scripting, and Markup Languages Survey 2019\u003c/figcaption\u003e\n  \u003c/figure\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\n  \u003cfigure\u003e\n    \u0026nbsp;\u0026nbsp;\u0026nbsp; \u003cimg src=\"./_examples_javascript_beginners/assets/images/2.2.2-google-trends-compare.png\" alt=\"Google Trends Language Compare \" title=\"Google Trends Language Compare \" width=\"1000\" border=\"2\" /\u003e\n    \u003cfigcaption\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; Image 02.02.02 - Google Trends - Language Compare \u003c/figcaption\u003e\n  \u003c/figure\u003e\n\u003c/p\u003e\n\n02.03. What is a scripting language?\n---------------------\n\n- A high-level programming language that is interpreted by another program at runtime rather than compiled by the computer's processor as other programming languages\n- A programming language designed for integrating and communicating with other programming languages\n    - Popular scripting languages are `JavaScript, VBScript, PHP, Perl, Python, Ruby, ASP`\n    - Since a scripting language is normally used in conjunction with another programming language, they are often found and used alongside `HTML, Java or C++`\n- The simple difference between scripting language and programming language is: Scripting languages do not require the compilation step and are rather interpreted\n    - `C program` needs to be compiled before running whereas normally, a scripting language like `JavaScript or PHP` need not be compiled\n- Scripting is interpreted based language, whereas Java, C, C++, and others are compiler-based language\n\n### What is a script?\n\n- A script is nothing but sets of instructions\n- Series of commands\n\n02.04. What can you do with JavaScript?\n---------------------\n02.04. Use of JavaScript\n---------------------\n\nFor a long time, JavaScript is used only as a `Client Side Front End Development language` to build browser-based interactive web pages. But currently due to huge community support `(Node or Nide.js) JavaScript is multi-purpose language` and used to develop:\n- Full-fledged Enterprise Web Application\n- Full-blown Mobile Apps\n- Real-time Networking Apps (Chats, Audio/Video Streaming Services)\n- Games\n- Command Line Tools (CLI-Command Line Interface utilities)\n\n### 02.04.01. JavaScript is used in billions of Web pages/web apps to add interactivity, validate forms and much more:\n\n- JavaScript gives HTML designers a `programming tool`\n- JavaScript can react to `events` (mouse click, hover (rollover, rollout), focus, blur)\n- JavaScript can be used to `validate` data (`Client-side validation`)\n- JavaScript can manipulate `HTML content` and `CSS styles` \n- Dynamic `drop-down menus`, HTML contents at run time/on the fly\n- Displaying live/current/dynamic `date and time (clocks)`\n- Displaying `pop-up windows` and `dialog boxes` (an `alert`, `confirm` and `prompt` dialog box)\n- Change the website's `behavior` and make it more `dynamic with advanced` web designs\n- Perform and `control transitions` and `animations`\n\n### However, there are more serious uses for javascript:\n\n- **Browser Detection** - Detecting the browser used by a visitor\n- **Cookies** - Storing information on the visitor's computer\n- **Control Browsers** - Opening pages in customized windows\n- **Validate Forms** - Validating inputs to fields before submitting a form\n\n02.05. Where does the JavaScript code run?\n---------------------\n\nJavaScript was originally designed and developed to run only in browsers. But now with the help of the `Node/Node.js (C++ program, that includes Google's V8 JavaScript engine)` we can build the back-end(server-side) for our web and mobile applications.\n\n### Common JavaScript Browser Engines\n\n| Browser                                      |   Engine                                  |\n| ---------------------------------------------|-------------------------------------------|\n| **Browser, Headless Browser, or Runtime**    | **JavaScript Engine**                     |\n| Mozilla                                      | Spidermonkey                              |\n| Safari**                                     | JavaScriptCore*                           |\n| IE and Edge                                  | Chakra                                    |\n| Chrome                                       | V8                                        |\n| TrifleJS                                     | V8                                        |\n| Node.js***                                   | V8                                        |\n| Io.js***                                     | V8                                        |\n| PhantomJS                                    | JavaScriptCore                            |\n| HTMLUnit                                     | Rhino                                     |\n| | |\n\n02.06. Who are using JavaScript? \n---------------------\n\n- JavaScript is used by:\n    - Front-end Developer\n    - Back-end Developer\n    - Full-stack Developer\n\n- Big companies and brands build entire applications: \n    - Netflix\n    - Walmart\n    - PayPal\n    - Microsoft\n    - Facebook (React.js)\n    - Google (Angular.js)\n    - Ebay\n    - Uber\n    - Groupon\n\n02.07. History of JavaScript\n---------------------\n\n- Invented by `“Brandan Eich”` at `Netscape` in `1995` originally named as `\"LiveScript\"`\n- `Netscape` \u0026 `Sun Java` agreements to rename `\"LiveScript\"` to `\"JavaScript\"` (As `java` is already popular in the market)\n- Not at-all related to `JAVA` (completely different in concept and design)\n- `Microsoft` has developed new version of \"JavaScript\" as `\"JScript\"` for `IE-3` in `1996`\n- JavaScript Submitted to `ECMAScript in 1997`\n\n02.08. JavaScript Vs ECMAScript\n---------------------\n\n| JavaScript                                  | ECMAScript                                  |\n| :-------------------------------------------|:--------------------------------------------|\n| JavaScript is `scripting programming language`        | ECMAScript is a `specification/standard`             |\n| JavaScript is invented by `Brandan Eich` at `Netscape`| ECMAScript standards defined by `ECMA (European Computer Manufacturers Association)` |\n| JavaScript is released in 1995                        | First ECMAScript standard published in 1997          |\n| JavaScript uses/follows ECMAScript specifications/standards | ECMAScript specification defines many new features for JavaScript |\n| | |\n\n02.09. Types of Script\n---------------------\n02.09. Various Scripting languages\n---------------------\n02.09. Client-Side Scripting Vs Server Side Scripting\n---------------------\n\n| Client-Side Scripting                     | Server-Side Scripting                     |\n| ------------------------------------------|-------------------------------------------|\n| Instruction for web Browser               | Instruction for web Server                |\n| Client-side scripting is used when the user's browser already has all the code and the page is altered based on the user's input     | Server-side scripting is used to create dynamic pages based several conditions when the user's browser requests the server       |\n| Response from a client-side script is faster as compared to a server-side script because the scripts are processed on the local computer | Response from a server-side script is slower as compared to a client-side script because the scripts are processed on the remote computer (server) |\n| Client-side scripting languages such as JavaScript, VBScript, etc. are interpreted and executed by the web browser | Server-side scripting languages such as ASP, PHP, Java, Python, Ruby, etc. run on the webserver and the output sent back to the web browser in HTML format\n| **Example**: Javascript, VB script, ActionScript, HTML, XHTML etc.  | **Example**: ASP, JSP, PHP, ASP#.Net, Perl, Ruby, Python, CGI etc.\n| | |\n\n02.10. Prerequisites of using HTML and JavaScript\n---------------------\n\n### Tools for building web sites-web pages/writing HTML, CSS \u0026 JavaScript\n\n1. **Text Editor/HTML Editor/Code Editor/Visual Code Editor** - `NotePad, NotePad++, SublimeText, Atom, Brackets, Coda, Visual Studio Code, DreamWeaver` etc.\n    - Just visit registered website of any of your favorite editor, download and install it (like **Visual Studio Code** = https://code.visualstudio.com)\n    - A JavaScript file (.js) is a text file itself consists of JavaScript code/statements, so to create/modify a JavaScript file we can use any text editors\n\n2. **Browsers - To view output of .html pages with .js files** - `Google Chrome, Mozilla Firefox, Internet Explorer, Safari` etc.\n    - Once the .html/.htm file created and saved, we can create a .js file and link within HTML and then we can see its output in any latest web browser\n\n3. **JavaScript Output / Debugging Tool (Developer console)** - \n    - alert() or window.alert()\n    - console.log()\n    - Google Chrome / Safari – `Developer Tools Inspect` / Inpsect element (in browser -\u003e Right Click on page -\u003e choose `Inspect / Inspect Element -\u003e Console Tab`\n    - Mozilla FireFox – `Firebug`\n\n\u003e **Note**: \u003cbr/\u003e \nUse `F12` key on the keyboard to open the `developer tools` then click on the `Console Tab`, OR on empty area in browser page `Right Click -\u003e Inspect (Developer Tool) -\u003e Console Tab`. Here You can write basic JavaScript statements and/or valid JavaScript code directly in browser console panel/tab and get the output\n\n\u003cp\u003e\n  \u003cfigure\u003e\n    \u0026nbsp;\u0026nbsp;\u0026nbsp; \u003cimg src=\"./_examples_javascript_beginners/assets/images/browsers_all_2.png\" alt=\"all browsers\" title=\"widely used browsers\" width=\"400\" border=\"2\" /\u003e\n    \u003cfigcaption\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; Image 02.10.01 - Widely used modern browsers\u003c/figcaption\u003e\n  \u003c/figure\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\n  \u003cfigure\u003e\n    \u0026nbsp;\u0026nbsp;\u0026nbsp; \u003cimg src=\"./_examples_javascript_beginners/assets/images/developer_tool_inspect_console.png\" alt=\"developer tool inspect console\" title=\"developer tool inspect console\" border=\"2\" /\u003e\n    \u003cfigcaption\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; Image 02.10.02 - Developer Tool Inspect Console\u003c/figcaption\u003e\n  \u003c/figure\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\n  \u003cfigure\u003e\n    \u0026nbsp;\u0026nbsp;\u0026nbsp; \u003cimg src=\"./_examples_javascript_beginners/assets/images/2.10-console-log-alert.png\" alt=\"developer tool inspect console\" title=\"developer tool inspect console\" border=\"2\" /\u003e\n    \u003cfigcaption\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; Image 02.10.03 - Developer Tool Inspect Console\u003c/figcaption\u003e\n  \u003c/figure\u003e\n\u003c/p\u003e\n\nSection 03. JavaScript Getting Started\n=====================\n\n03.01. How to write Javascript?\n---------------------\n03.01. JavaScript in HTML\n---------------------\n\n- The HTML `\u003cscript\u003e.....\u003c/script\u003e` tag is used to embed/insert/implement a JavaScript programs/code into any part of an HTML document/page\n- The `\u003cscript\u003e.....\u003c/script\u003e` tag specifies that we are using JavaScript\n- The `\u003cscript\u003e.....\u003c/script\u003e` element can be placed in the `\u003chead\u003e`, or `\u003cbody\u003e` section of an HTML document\n- Each `\u003cscript\u003e.....\u003c/script\u003e` tag blocks the page rendering process until it has fully downloaded and executed the JavaScript code\n  - So the best practice is to place/add the `\u003cscript\u003e.....\u003c/script\u003e` at the bottom/end of `body` tag/section ie. just before the closing `\u003c/body\u003e` tag\n\n\u003e **Note**: \u003cbr/\u003e\nJavaScript is the default scripting language in HTML. The old HTML standard attributes like `type=\"text/javascript\"` and `language=\"javascript\"` no longer required in modern browser \n\n\u003e **Syntax \u0026 Example**: `03.01.js.script.tag.html`\n```html\n\u003chead\u003e\n\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n    \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\"\u003e\n    \u003ctitle\u003e03.01.js.script.tag.html\u003c/title\u003e\n\n    \u003c!-- internal style --\u003e\n    \u003cstyle\u003e\n      /* css selector: { property:value; } */\n      body {\n        font-family: arial;\n      }\n    \u003c/style\u003e\n\n    \u003c!-- internal JavaScript - head section --\u003e\n    \u003cscript\u003e\n      // Write all JavaScript code here\n      alert('welcome to JavaScript');\n\n    \u003c/script\u003e\n    \n\u003c/head\u003e\n\n\u003cbody\u003e\n    \n    Content\n\n    \u003c!-- internal JavaScript - body section --\u003e\n    \u003cscript\u003e\n      /* Write all JavaScript code here */\n      console.log('welcome to JavaScript');\n      document.write('This is dyanamic content. Hello All, Lets write something on web page');\n      \n    \u003c/script\u003e\n    \n\u003c/body\u003e\n```\n\n03.02. Where to write JavaScript in HTML?\n---------------------\n03.02. Where to embed include write put JavaScript in HTML?\n---------------------\n\n### JavaScript provides 3 places to write the JavaScript code in our webpage:\n1. Inside the HEAD section\n2. Inside the BODY section\n3. External JavaScript .js file (separation of concern)\n\n### 03.02.01. Inside the HEAD section (code between the head tag)\n\n- JavaScript programs/code/statements can be placed in the `\u003chead\u003e` section of an HTML page\n- As each `\u003cscript\u003e.....\u003c/script\u003e` tag blocks the page rendering process until it has fully downloaded and executed the JavaScript code so placing them in the `head section (\u003chead\u003e element` of the document without any valid reason will significantly impact your website performance\n\n\u003e **Syntax \u0026 Example**: `03.02.01.js.head.html` \n```html\n\u003chead\u003e\n\n    \u003c!-- internal JavaScript - head section --\u003e\n    \u003cscript\u003e\n        // Write all JavaScript code here\n        alert('welcome to JavaScript written in head section');\n\n    \u003c/script\u003e\n\n\u003c/head\u003e\n```\n\n### 03.02.02. Inside the BODY section (code between the body tag)\n\n- JavaScript programs/code/statements can be placed in the `\u003cbody\u003e` section of an HTML page\n- As blocking nature of `\u003cscript\u003e.....\u003c/script\u003e` tag ideally, scripts should be placed at the end of the `body section`, just before the `closing \u003c/body\u003e tag`, it will make your web pages load faster since it prevents obstruction of initial page rendering\n\n\u003e **Syntax \u0026 Example**: `03.02.02.js.body.html`\n```html\n\u003cbody\u003e\n\n    page content\n\n    \u003c!-- internal JavaScript - body section --\u003e\n    \u003cscript\u003e\n        // Write all JavaScript code here\n        alert('welcome to JavaScript written in body section');\n        console.log('welcome to JavaScript written in body section');\n        document.write('\u003ch2\u003ewelcome to JavaScript written in body section\u003c/h2\u003e');\n\n    \u003c/script\u003e\n\n\u003c/body\u003e\n```\n\n### 03.02.03. External JavaScript .js file (separation of concern)\n\n- We can easily write JavaScript code in between the `script element`. In a real-world application, we have 100+ maybe even 1000+ lines of code, we don't want to write all that code inline here\n- We must have to `extract and separate` our JavaScript behavior code from our HTML markup code\n- A simple thumb-rule is if we have a lot of JavaScript code, we can put it into a separate file\n- We can use/add/attach an external JavaScript file by using `\u003cscript\u003e` tag with `src (source)` attribute:\n    - ```\u003cscript src=\"path/scriptfile.js\"\u003e\u003c/script\u003e```\n    - One can provide a `full URL (absolute path)` or `relative path` from the current page\n- We can create a single external JavaScript file and embed it in many/any HTML page which provide `code re-usability`\n\n### 03.02.04. Advantages of External JavaScript \n\n- It separates HTML and JavaScript code (separation of concern)\n- Code re-usability\n- It makes HTML and JavaScript file/code easier to read, maintain and more meaningful/semantic\n- Web page loads faster /increase the speed of the webpage (Cached JavaScript files)\n\n\u003e **Note**: \u003cbr/\u003e\nUsually, when an external JavaScript file is downloaded for the first time, it is stored in the browser's cache (like images and style sheets), so it won't need to be get downloaded multiple times from the web server that makes the web pages load faster/quickly.\n\n\u003e **Syntax \u0026 Example - `.html file`**: `03.02.03.js.external.html`\n```html\n\u003cbody\u003e\n\n    page content\n\n    \u003c!-- include external JavaScript - body section --\u003e\n    \u003cscript src=\"./03.script.js\"\u003e\u003c/script\u003e\n    \n\u003c/body\u003e\n```\n\n\u003e **Syntax \u0026 Example - `.js file`**: `03.02.03.script.js`\n```javascript\n// external js file\n// Write all JavaScript code here\n\nalert('welcome to JavaScript written in external file');\nconsole.log('welcome to JavaScript written in external file');\ndocument.write('\u003ch2\u003ewelcome to JavaScript written in external file\u003c/h2\u003e');\n```\n\n03.03. JavaScript Code structure\n---------------------\nThe syntax of JavaScript is the `set of rules` that define a correctly structured JavaScript program. Let's study some of the building blocks of JavaScript code:\n\n### 03.03.01. JavaScript Statements\n\n- One line of JavaScript Code is one JavaScript Statement / Instruction / Command\n- Statements are a command to Browser to do something / perform actions\n- A Statement is a piece of code that expresses an action to take place\n- JavaScript code/program (or just JavaScript) is a sequence of statements\n- Statements are written in-between `\u003cscript\u003e.....\u003c/script\u003e` tag\n- Statements are separated by `Semicolon;` so we may write many statements in a line (optional)\n- JavaScript ignores extra line breaks and white spaces\n- JavaScript is case sensitive language (VB, Pascal, HTML are case insensitive)\n- JavaScript is interpreted not compiled (write and handed over to the web browser)\n- All statement in JavaScript should be terminated by a `Semicolon;` \n\n\u003e **Note**: \u003cbr/\u003e\nJavaScript statements are composed of: **`Values, Operators, Expressions, Keywords, and Comments`**\n\n### 03.03.02. Whitespace and Line Breaks\n\n- JavaScript ignores `spaces, tabs, and newlines` that appear in JavaScript programs\n- We can freely use spaces, tabs, and newlines to format and indent programs in a neat-clean and consistent way that makes the code easy to read and understand (not advisable)\n\n### 03.03.03. Semicolons\n\n- JavaScript statements are generally followed by a `semicolon; character`\n- A semicolon may be omitted in `most cases` when a line break exists\n- JavaScript interprets the line break as an `implicit` semicolon, called an `automatic semicolon insertion`\n- **In most cases, a newline implies a semicolon, But “in most cases” does not mean “always”!**\n\n\u003e **Note**: \u003cbr/\u003e\nIt is a good programming practice to use semicolons; after every statement\n\n### 03.03.04. Case Sensitivity\n\n- JavaScript is a case-sensitive language\n- in Javascript variables, language keywords, function names, and other identifiers must always be typed with a consistent capitalization of letters\n- **Example**: `var firstName='Dinanath';` and `var FirstName='Dinanath';` here `firstName \u0026 FirstName` are different ie. two different variable\n\n\u003e **Note**: \u003cbr/\u003e\nTake care/precautions while writing variable and function names in JavaScript\n\n### 03.03.05. JavaScript Code Blocks\n\n- JavaScript commands/statements/code can be grouped together in code blocks, `inside curly brackets {...}`\n- Grouped statements/lines form code blocks\n- The purpose of code blocks is to define statements to be executed together like a single JavaScript command\n- An often occurrence of a code block in JavaScript is a JavaScript `function`\n\n\u003e **Syntax \u0026 Example**: `03.03.05.script.js`\n```javascript\n// external js file\n// Write all JavaScript code here\n\n// define function - block of code to show welcome message\nfunction sayHello() {\n  alert('Hello All! Welcome to JavaScript!!');\n}\n\n// define function - block of code to show total of two numbers\nfunction showTotal() {\n  var num1 = 10;\n  var num2 = 20;\n  var total = num1 + num2;\n  alert('Total is : ' + total);\n}\n\n// invoke / run  / call a function\nsayHello();\nshowTotal();\n```\n\n03.04. JavaScript Keywords\n---------------------\n\nUsually, JavaScript commands/statements start with a `specific keyword` which defines what `action/function` should the browser will perform/do:\n\n| Keyword           | Keyword          |Keyword           | Keyword          |Keyword           |\n| ------------------|------------------|------------------|------------------|------------------|\n| break             | do ... while     | if ... else      | try ... catch    | const            |\n| continue          | for              | return           | var              | class            |\n| debugger          | function         | switch           | let              | import           |\n| | | | | | \n\n### 03.04.01. Reserved Keywords\n\nJavaScript has several reserved keywords. These are the words that you cannot use as identifiers (variable names, function names, and loop labels) in your JavaScript programs. The following list shows the keywords that are reserved in `ECMAScript 6`. It also includes keywords that are `reserved for future` as well as keywords that are `disallowed in strict mode`.\n- arguments, await, break, case, catch, class, const, continue, debugger, default, delete, do, else, enum, eval, export, extends, false, finally, for, function, if, implements, import, in, instanceof, interface, let, new, null, package, private, protected, public, return, static, super, switch, this, throw, true, try, typeof, var, void, while, with, yield, \n\n03.05. Comments\n---------------------\n- The comments are a meaningful way to `deliver the message (description to code)` for others/for future reference and to understand/follow the code statements/lines\n- Comments are special lines written for other developers as a reference purpose and browser ignores while interpreting\n- It is used to add information about the code, warnings or suggestions so that end-user can easily interpret the code (`Why and How of code/program/logic`)\n- Comments are used to explain code/programs/statements and to make it more readable for developers\n- A comment is ignored by the JavaScript engine embedded in the browser\n- Comments can also be used to prevent the execution of certain logic when testing code\n- Comments can be put into any place of a script, they don’t affect its program execution because the engine simply ignores them\n- Comments help to `make code easy to understand` and `it avoids the unnecessary code`\n\n### 03.05.01. Types of JavaScript Comments\n\nThere are two types of comments in JavaScript:\n1. Single-line Comments\n2. Multi-line Comments\n\n#### 03.05.01.01. Single-line Comments\n\n- Single-line JavaScript comments are used for one line of comment only\n- Single-line comments starts with `two forward slash`: **// is single comment**\n- Any statements between `//` till the end of the line will be ignored by JavaScript (not be executed)\n- Single-line comments do not need closure/closing\n\n\u003e **Syntax \u0026 Example**: `03.05.script.js`\n```javascript\n// external js file\n// Write all JavaScript code here\n\n// show alert box\nalert('Welcome to JavaScript!');\n\nvar firstName = 'Dinanath'; // variable to store firstName\nvar lastName = 'Jayaswal'; // variable to store lastName\n```\n\n#### 03.05.01.02. Multi-line Comments\n\n- Multi-line comments usually comment out a block of code\n- Multi-line comments in JavaScript can comment on bigger parts (a few lines) of code\n- Multi-line comments are more convenient as it can be used to comment single as well as multi-line comments\n- Multiline comments start with `forward slash and an asterisk, /* and also end with an asterisk and a forward slash */`:  /* multi-line comment */\n- Multi-line comments need closing\n- Multi-line comments are more often used for `formal documentation`\n\n\u003e **Syntax \u0026 Example**: `03.05.script.js` \n```javascript\n/* show alert box */\nalert('Welcome to JavaScript!');\n\n/* This is a multiline comment.\nA code block can be commented on. */\n\n/* var firstName = 'Dinanath'; // variable to store firstName\nvar lastName = 'Jayaswal'; // variable to store lastName */\n```\n\nSection 04. JavaScript Language Fundamentals\n=====================\n\n04.01. Generating Output\n---------------------\n- JavaScript does not have any `display or built-in print` functions\n- Many times we may need to generate output from your JavaScript code like `see the value of a variable`, or `write a message to browser console` to help you `debug an issue` in your running JavaScript code, and so on\n- That is why you have to use the JavaScript output function to generating output `(browser window or browser console dialog boxes, writing output into an HTML element, etc.)`\n- Using different output methods knowledge will help you while debugging or rewriting your code more conveniently\n\n### Different ways to show output/display data\n\n1. Writing into an alert box with `alert() or window.alert()`\n2. Writing into browser console with `console.log()`\n3. Writing into the HTML / Browser Window  with `document.write()`\n4. Write into an element of HTML / Inserting Output Inside an HTML Element with `innerHTML`\n\n#### 04.01.01. Displaying Output in Alert Dialog Boxes: alert() or window.alert()\n- One can use `alert dialog boxes` to display the message or output data to the user \n- An alert dialog box is created using the `alert() or window.alert()` method\n- A small pop-up box appears with a closing button to close alert-box\n- This method is great for short and rapid informative messages which can be instantly closed\n\n\u003e **Syntax \u0026 Example**: `04.01.01.script.js`\n```javascript\n// external js file\n// Write all JavaScript code here\n\nalert('I am Dinanath Jayaswal');\nwindow.alert('We are learning JavaScript');\n```\n\n#### 04.01.02. Writing Output to Browser Console: console.log()\n\n- Programmers can easily output a message or write data to the browser console using the `console.log()` method\n- `console.log()` function is mainly/widely used for `debugging code` as it makes the JavaScript output print to console\n- This is a simple, easy but very powerful method for generating detailed output\n\n\u003e **Syntax \u0026 Example**: `04.01.02.script.js`\n```javascript\n// external js file\n// Write all JavaScript code here\n\nconsole.log('I am Dinanath Jayaswal');\nconsole.log('We are learning JavaScript');\n```\n\n\u003e **Note**: \u003cbr/\u003e\nUse `F12` key on the keyboard to open the `developer tools` then click on the `console tab`. You can write basic JavaScript statements directly in the browser console panel/tab and get the output.\n\n#### 04.01.03. Writing Output into the HTML / Browser Window: document.write()\n\n- `document.write()` method is used to write the content to the current document while document is being parsed\n- Programmers do ues document.write() for `testing purposes`\n\n\u003e **Syntax \u0026 Example**: `04.01.03.script.js`\n```javascript\n// external js file\n// Write all JavaScript code here\n\ndocument.write('I am Dinanath Jayaswal');\ndocument.write('We are learning JavaScript');\n```\n\n#### 04.01.04. Inserting Output Inside an HTML Element: innerHTML\n\n- We can write or insert output inside an HTML element using the element's `innerHTML` property\n- First we need to select the element using a method such as `document.getElementById(id)` \n\n\u003e **Note**: \u003cbr/\u003e\nHTML element manipulating is fully dependent on JavaScript DOM manipulation concepts\n\n\u003e **Syntax \u0026 Example**: `04.01.04.script.js`\n```javascript\n/// external js file\n// Write all JavaScript code here\n\n// Writing text string inside an element\ndocument.getElementById('mainHeadingText').innerHTML = 'Heading Text change dynamically on run-time';\n\nvar paraText = document.getElementById('mainParaText');\nparaText.innerHTML = '\u003cstrong\u003eThis Paragraphic text inserted dynamically through innerHTML method.\u003c/strong\u003e';\n```\n\nWith JavaScript, we can do many cool and dynamic pieces of stuff (Image Gallery, Games, Forms) but for that one should be familiar with core essentials/building blocks of JavaScript programming language like Variables, Functions, Operators, Loops, Conditional Statements, Array, Objects, Events, DOM (Document Object Model), etc. which will cover in coming lessons.\n\nSection 05. Variables\n=====================\n\n05.01. What is Variable?\n---------------------\n\nVariables are one of the most fundamental concepts in JavaScript and other all programming languages of the world.\n\n- A variable is `container to store/hold the data/information`\n- Developers/Programmers use Variable to `store/hold the data/information temporarily` in computer memory \n- A variable is a kind of data holder where we can store some value for programming or calculation purpose\n- A JavaScript variable is simply a `name of the storage location (named containers/named storage)` for data\n- Variables are symbolic names for values \n- Variables are used to store data of different types like a string of text, numbers, boolean values like true/false, an array of data, etc. \n- The data or value stored in the variables can be set, updated, and retrieved whenever needed\n- Variables are declared using the keyword `var` keyword\n- The `assignment operator (=)` is used to assign value to a variable, like this: `var varName = value;` or `var firstName = 'JavaScript';`\n- By default value of variable defined in JavaScript is `undefined` (variable is defined but value not assigned: `var firstName;` or `let lastName; console.log(firstName, lastName); ` // undefined)\n\n\u003chr/\u003e\n\n- **Example**: Variables are like `box or an envelope` which we use to `organize various kinds of stuff` and put a `label` on each box or an envelope\n- **Example**: Variable declaration and assignment is just `like Maths \u0026 Algebra`: `x = 10`; and in JavaScript we write `var x = 10;`\n\n\u003chr/\u003e\n\n\u003e **Note**: \u003cbr/\u003e\nIn ES6 `'let'` and `'const'` keywords are used to defined variables\n\n\u003e **Note**: \u003cbr/\u003e\nAs a best practice of ES6, from now onwards variables must be define with `let` keyword: `let techName = 'JavaScript' ; `\n\n\u003chr/\u003e\n\n\u003e **Syntax \u0026 Example**: `05.01.script.js`\n```javascript\n// variables defined to hold different types of data\nvar techName = 'JavaScript'; // String literal \nvar version = 6; // Number literal\nvar isDone = true; // Boolean literal\n\nconsole.log('Learning '+techName+version);\n```\n\n05.02. Declaring variable without a value\n---------------------\n05.02. Creating a variable without a value\n---------------------\n\nVariables can also be declared without having any initial values assigned to them. This is useful for variables that are supposed to hold values like user inputs, calculations, status updates, etc.\n\n\u003e **Syntax \u0026 Example**: `05.01.script.js`\n```javascript\n// Declaring Variables\nvar techName;\nvar version;\nvar isDone;\n\n// Assigning value\ntechName = 'JavaScript';\nversion = 6;\nisDone = true;\n\nconsole.log('Learning '+techName+version);\n\n// ------------------------------\n\n// Declaring Variable\nvar userName;\n\n// Assigning value\nuserName = 'Dinanath';\n\nconsole.log('Welcome '+userName);\n```\n\n05.03. Declaring multiple variables at once\n---------------------\n\nWe can also `declare multiple variables` and set their initial values in a single statement, each variable is `separated by comma`.\n\n\u003e **Syntax \u0026 Example**: `05.01.script.js`\n```javascript\n// Declaring multiple variables\nvar techName = 'JavaScript', version = 6, isDone = true;\n\n// Declaring multiple variables in multiple lines for readability\nvar techName = 'JavaScript', \nversion = 6, \nisDone = true;\n\nconsole.log('Learning '+techName+version);\n\n// ------------------------------\n\n// Declaring multiple variables\nvar firstName = 'Dinanath', lastName = 'Jayaswal', age = 35, isMarried = 'true';\n\n// Declaring multiple variables in multiple lines for readability\n/* var firstName = 'Dinanath', \nlastName = 'Jayaswal', \nage = 35, \nisMarried = 'true'; */\n\nconsole.log('I am ' + firstName + ' ' + lastName);\n```\n\n05.04. Variable Naming Conventions\n---------------------\n05.04. Variable Naming Conventions (Identifiers)\n---------------------\n\nAll JavaScript variables must be `identified`/referred/defined/named with `unique names`, called as `identifiers`. The naming rules in JavaScript are not much different from any other programming language. \n\n- There are some rules while declaring/naming a JavaScript variable (also known as `identifiers`)\n  - Identifiers are `simply names` in JavaScript\n  - Identifiers are used to name variables, keywords, functions, and labels\n  - Identifiers can be `short names/nick names` (like name, age, num1, isDone, sum) or more descriptive names (firstName, totalDashboards, isSeniorCitizen)\n\n**The basic rules for defining/assigning names for variables (unique identifiers) are:**\n\n- A variable name must `start with a letter, underscore (_), or dollar sign ($)`\n  - **Example**: var firstName, var _firstName, var $firstName;\n- Names can contain letters, digits, underscores, and dollar signs\n  - **Example**: var $num_total1; \n- A variable name `cannot start with a number or special characters`\n  - **Example**: var 1num_total, var .num_total\n- A variable name `cannot contain spaces`\n  - **Example**: var num total;\n- A variable Names are `case sensitive`\n  - **Example**: var firstName='Dinanath'; and var FirstName='Dinanath'; here `firstName \u0026 FirstName` are different ie. two different variable\n- A variable name cannot be a `JavaScript keyword or a JavaScript reserved word`\n   - **Example**: var var; var switch; var for; var true;\n- One should Always give `meaningful/descriptive names` to variables\n- for naming the variables that contain multiple words, `camelCase` method is commonly used (camelCase is the default method for identifier naming)\n\n\u003e **Note**: \u003cbr/\u003e\nIn the programming world, there have been two most popular methods/mechanism of writing multiple words identifiers: (Underscore, Camel Case)\n\n1. **Underscore**: first_name, last_name, date_of_birth, is_passed, native_place\n2. **Camel Case:**: firstName, lastName, dateOfBirth, isPassed, nativePlace  OR \u003cbr/\u003e : FirstName, LastName, DateOfBirth, IsPassed, NativePlace \n\n\u003e **Syntax \u0026 Example**: `05.04.script.js`\n```javascript\n// variables defined to hold different types of data\nvar _firstName = 'JavaScript';\nvar $version = 6;\nvar $num_total1 = 10;\n\nwindow.alert('variables details: ' +  _firstName + ' ' + $version + ' ' + $num_total1);\n\n// wrong identifiers\n// var #name;\n```\n\n05.05. Variable Scope\n---------------------\n\nThe scope of a variable is the region/coverage of your program in which it is defined and exist/available. JavaScript variables have two scopes:\n1. Local Variables\n2. Global Variables\n\n#### 05.05.01. Local Variables\n\n- A JavaScript local variable is declared `inside block or function`\n- It is accessible within the `function or blocks only`\n- A local variable will be `visible only within a function` where it is defined\n- `Function parameters` are always local to that function\n\n\u003e **Note**: \u003cbr/\u003e\nIn the function body, a `local variable takes precedence` over a global variable with the same name.\n\n\u003e **Syntax \u0026 Example**: `05.05.01.script.js`\n```javascript\n// global variable\nvar globalName = 'Global';\n\nwindow.alert(globalName);\n\nfunction showName() {\n  // local variable\n  var localName = 'Local';\n\n  window.alert(localName);\n  window.alert(globalName); // recall global variable\n}\n\n// invoke/call/run function\nshowName();\n\n// error - as local variable not exist/available outside of block { }\nwindow.alert(localName);\n```\n\n#### 05.05.02. Global Variables\n\n- A variable `declared outside the function/at the root` or declared `with window object` is known as a global variable \n- A JavaScript global variable is accessible from any function \n- A global variable has a global scope which means it can be defined and accessible anywhere in JavaScript code/program\n\n\u003e **Syntax \u0026 Example**: `05.05.02.script.js`\n```javascript\n// global variable\nvar globalName = 'Global';\n\nwindow.alert(globalName);\n\nfunction showName() {\n  // local variable\n  var globalName = 'Local';\n\n  window.alert(globalName);\n\n  // define global variable with window\n  window.globalVersion = 29;\n  window.alert('global variable from inside function: ' + window.globalVersion);\n}\n\n// invoke/call/run function\nshowName();\n\n// access global variable defined inside function\nwindow.alert('global variable from outside function: ' + window.globalVersion);\n```\n\n05.06. The let and const keywords ES6\n---------------------\nES6 introduces two new keywords `let` and `const` for declaring variables. The `var, let and const` keywords are almost the same, just a few differences with the scope.\n\n- In older programs` var` is used a lot which declares a variable `(function-scoped variables)`, but in a slightly different `old` way, with scope issues \n- Both `let` and `const` keywords declare variables, `scoped at block-level ({})` \n- Block scoping means that a new scope is created `between a pair of curly brackets {}`\n\n### 05.06.01. The let Keyword\n\n`ES6` introduces the new `let` keyword for declaring variables. Prior to ES6, the only way to declare a variable in JavaScript was the var keyword. Let's see what's the difference:\n- Variables declared with the `var` keyword are `function-scoped` and can be `hoisted` at the top within its scope\n- Variables declared with `let` keyword are `block-scoped ({})` and they are not hoisted\n\n\u003e **Syntax \u0026 Example**: `05.06.01.script.js`\n```javascript\n// traditional var syntax\nvar techName1 = 'JavaScript';\n\nfor(var i = 1; i \u003c= 5; i++) {\n  console.log('i : ' + i); // 1,2,3,4,5\n  console.log('inside block:' + techName1);\n  var version1 = 100;\n}\nconsole.log('outside: ' + i); \nconsole.log('outside: ' + version1); \n\n// ------------------------------\n\n// ES6 syntax\nlet techName2 = 'LiveScript';\n\nfor(let n = 1; n \u003c= 5; n++) {\n  console.log('n : ' + n); // 1,2,3,4,5\n  console.log('inside block:' + techName2);\n  let version2 = 100;\n}\n\nconsole.log(n); // undefined\nconsole.log('outside: ' + version2);  // undefined\n```\n\n### 05.06.02. The const Keyword\n\n`ES6` introduces the new `const` keyword for declaring variables. \n- Use `const` to declare a constant `(read-only / unchanging)` variable\n- Constants are `read-only`, you `cannot reassign new values` to them\n- In Programm/logic when the variable will never change, they can be declared as `const`\n- constants are named using capital letters and underscore **Example**: const NATIVE_CITY\n- `const` are also `block-scoped` like `let`\n- However, you can change `object properties` or `array elements`\n\n\u003e **Syntax \u0026 Example**: `05.06.02.script.js`\n```javascript\n// traditional var syntax\nvar PI1 = 3.14;\nconsole.log(PI1); // 3.14\n\nPI1 = 100;\nconsole.log(PI1); // 100\n\n// ------------------------------\n\n// ES6 syntax\nconst PI2 = 6.28;\nconsole.log('ES6 syntax const: ' + PI2); // 6.28\n\nPI2 = 100; // error\n```\n\nSection 06. Data types\n===================== \n\n06.01. Data types\n---------------------\n\nA variable in JavaScript can contain `any type of data`. Data types specify what `kind of data` can be stored and manipulated within the variable in a program. In JavaScript, different data types are available to hold different types of values/data. There are `two main categories/types` of data types in JavaScript:\n1. Primitive (Primary or Value) data type\n    - String\n    - Number\n    - Boolean\n    - Undefined\n    - Null\n    - Symbol (newly introduced in ES6)\n2. Non-primitive (Reference or Composite) data type\n    - Array\n    - Object\n    - Function\n\n06.02. Primitive data type\n---------------------\n06.02. Primitive, Primary or Value data type\n---------------------\n\nPrimitive data types can `hold only one value at a time`. Primitives are `compared by value`. Two values are strictly equal if they have the same value.\n\nThere are different types of primitive data types in JavaScript. They are as follows:\n\n| Data Type       | Description                                                                 |\n| ----------------|-----------------------------------------------------------------------------|\n| String          | represent textual data. e.g. \"welcome\" or 'to javascript'                   |\n| Number          | represents numeric values e.g. 10, 100.29                                   |\n| Boolean         | represents boolean value either false or true                               |\n| Undefined       | represents an undefined value (a variable declared but value not assigned)     |\n| Null            | represents null i.e. no value at all                                        |\n| | |\n\n### 06.02.01. String\n\n- The string data type is used to `represent textual data (i.e. sequences of characters)`\n- Strings hold information in `words/text`\n- A string in JavaScript must be surrounded by `\"double\"` or `'single'` quotes\n- **Example**: `06.02.script.js`\n\n```js\nvar firstName = \"Java\"; \nvar lastName = 'Script';\n```\n\n### 06.02.02. Number\n\n- The number data type simply defined without quotes is used to represent positive or negative numbers with or without a decimal place\n- Many mathematical operations can be done on numbers, e.g. `multiplication *, division /, addition +, subtraction`, and so on\n- **Example**: \n\n```js\nvar age = 25; \nvar id = 1;\n```\n\n### 06.02.03. Boolean\n\n- The Boolean data type can hold only two values: `true or false`\n- true = ON / yes / correct / 1, false = OFF / no, incorrect / 0\n- Boolean data types is often used in `conditional testing` of code\n- **Example**: \n\n```js\nvar isDone = true; \nvar isMarried = false;\n```\n\n### 06.02.04. Undefined\n\n- The meaning of undefined is `“value is not assigned”`\n- The undefined data type can only have one value-the special value undefined\n- A Variable has been declared, but `not assigned a value`\n- A variable `without a value`, The type is also undefined\n- **Example**: \n\n```js\nvar firstName;\nvar country;\n```\n\n### 06.02.05. Null\n\n- A null value means that there is no value\n- The special value which represents `“ nothing”, “empty” or “value unknown”`\n- It is not equivalent to an empty string ('' or ' ', \"\", \" \"), it is simply nothing\n- **Example**: \n\n```js\nvar firstName = null;\nvar id = null;\n```\n\n06.03. Non-primitive data type\n---------------------\n06.03. Non-primitive, Reference or Composite data type\n---------------------\n\n- Non-primitive/Reference data types can hold `collections of values and more complex entities`\n- Non-primitive values are being compared by `reference` instead of value\n- Data does not store in the variables but stored on the heap - a dynamically allocated memory reference\n- Its a pointer to a location in memory, accessed by reference\n\nThere are different types of non-primitive data types in JavaScript. They are as follows:\n\n| Data Type       | Description                                                           |\n| ----------------|-----------------------------------------------------------------------|\n| Array           | represents a group of similar value (multiple values in one variable) |\n| Object          | represents an instance through which we can access members (property \u0026 value) |\n| Function        | represents function (bunch/block of line to execute once)             |\n| | |\n\n06.04. JavaScript has Dynamic Types\n---------------------\n\nWe have two types of programming languages:\n1. Static languages\n    - Declare a variable, the type of the variable is set and it cannot be changed in the future\n2. Dynamic languages\n    - Variable can change at run time (one variable can store different types of value as per requirement, we again assign any value any time as per logic, requirements)\n\n- A JavaScript `variable can contain/hold any data ie. any type of data`, A variable at one moment can be a number and at another moment be a string, boolean \n- It simply means that `same variable can be used to hold different data types`\n- JavaScript is a dynamic type language, means you don't need to specify a type of the variable because it is dynamically used by JavaScript engine\n\n\u003e **Syntax \u0026 Example**: `06.04.script.js`\n```javascript\nlet name = 'JavaScript';\nname = false;\nname = 100;\n\nalert(name);\nalert(typeof(name));\n```\n\n06.05. The typeof Operator\n---------------------\n\n- The typeof operator returns the `type of the argument`\n- It’s useful to process values of different types differently or want to perform a quick data type check\n- The typeof operator can be used to find out what `type of data a variable` or operand contains\n- It can be used with or without parentheses `(typeof(x)` or `typeof x`\n\n\u003e **Syntax \u0026 Example**: `06.05.script.js`\n```javascript\n// use typeof to find data type of variables\n// Strings\nalert(typeof \"Hello\"); // \"string\"\nalert(typeof '12'); // \"string\"\n\n// Numbers\nconsole.log(typeof(100)); // \"number\"\nconsole.log(typeof(100.29)); // \"number\"\n\n// Booleans\nalert(typeof true); // \"boolean\"\nalert(typeof(1 == 2)); // \"boolean\"\n\n// Undefined\nconsole.log(typeof undefined); // \"undefined\"\n\nvar init;\nconsole.log('type of init: ' + typeof init); // \"undefined\"\n\n// Null\nconsole.log(typeof null); // \"object\"\nvar initObject = null;\nconsole.log('type of initObject: ' + typeof initObject);  // \"object\"\n\n// Objects\nalert(typeof {name: 'Dinanath', age: 35}); // \"object\"\nalert(typeof document); // \"object\"\nalert(typeof window); // \"object\"\n\n// Arrays\nvar techArray = [];\nconsole.log('type of techArray: ' + typeof techArray);  // \"object\"\nconsole.log(typeof ['JavaScript', 'jQuery', 'Angular']);  // \"object\"\nconsole.log(typeof ['Dinanath', 35, 'India']);  // \"object\"\n\n// Functions\nconsole.log(typeof function(){}); // \"function\"\nconsole.log(typeof alert); // \"function\"\nconsole.log(typeof window.alert); // \"function\"\n\n// Symbol\nalert(typeof Symbol(\"dob\")); // \"symbol\"\n```\n\n06.06. Type conversion\n---------------------\n06.06. typeof parseInt parseFloat\n---------------------\n\n- Type conversion is nothing but taking a variable and changing its data type as per needs requirements and logic\n- In JavaScript as and when we take an `input in the form, its data type is a string by default`, so do any calculations we need to `parse` to `integer/int or the number`\n- Data type conversion can be either implicit (automatic) or explicit (forcefully/manually)\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Number to String conversion\nlet num1 = 100;\n\nconsole.log(num1);\nconsole.log(typeof num1);\nconsole.log(num1.length); //error as number type variables does not have length\n\nnum1 = String(num1);\n\nconsole.log(num1);\nconsole.log(typeof num1);\nconsole.log(num1.length);\n\n// Boolean to String conversion\nlet boolValue1 = String(false);\n\nconsole.log(boolValue1);\nconsole.log(typeof boolValue1);\n\n// Date to String conversion\nlet curDate = String(new Date());\n\nconsole.log(curDate);\nconsole.log(typeof curDate);\n\n// Array to String conversion\nlet numArray = String([1,2,3,4,5]);\n\nconsole.log(numArray);\nconsole.log(typeof numArray);\n\n// toString() method\nlet curString = (1000).toString\nlet curString = (true).toString\n\n//  String to Number conversion\n\nlet num2 = '100';\n\nconsole.log(num2);\nconsole.log(typeof num2);\nconsole.log(num2.toFixed(2)); //helps to fix decimals - error as string type variables does not have any properties or methods related to number\n\nnum2 = Number(num2);\n\nconsole.log(num2);\nconsole.log(typeof num2);\nconsole.log(num2.toFixed(2));\n\n// Boolean to Number conversion\nlet boolValue2 = Number(false);\n\n// parseInt() method\n\nlet curNumber = parseInt('100');\nlet curNumber = parseFloat('100.41');\n```\n\n06.07. Type coercion\n---------------------\n\n- Type coercion simply refer to the JavaScript ability to convert type automatically (developer does not do it but JavaScript does it for us)\n- Type coercion is the process of converting a value from one type to another (such as string to a number, object to boolean, and so on)\n- JavaScript engine converts the type as per its rules (implicit ie. automatic conversion of data type)\n\n\u003e **Syntax \u0026 Example**: \n```javascript\nconst num1 = '20';\nconst num1 = 10;\n\nconst sum = (num1) + (num2);\nconsole.log(sum);\nconsole.log(typeof sum);\n```\n\nSection 07. Operators\n=====================   \n\n07.01. What is the Operator?\n---------------------\n- We know/use many operators since our initial school days, they are things like addition +, multiplication *, subtraction -, open-close round bracket ( ) or square bracket [ ]\n- Operators are symbols/keywords that tell the JavaScript engine to `perform some sort of actions`\n- JavaScript operators are symbols that are used to perform operations on operands\n- Operators used along with our variables and constants to create\nexpressions to implement logic and algorithms\n\n\u003e **Note**: \u003cbr/\u003e\nLet us take a simple expression `var sum = 1 + 2`;\n- Here 1 and 2 are called `operands` and \n- `=` \u0026 `+` are called the `operator`\n- `= is the assignment` operator, `+ is the arithmetic` operator\n\n\u003e **Syntax \u0026 Example**: `07.01.script.js`\n```javascript\n// Lets take a look on simple expression \nvar sum = 1 + 2;\n\n// Here 1 and 2 are called `operands` and \n// `=` \u0026 `+` are called the `operator`\n// `= is the assignment` operator, `+ is the arithmetic` operator\n```\n\n**JavaScript supports the following types of operators**:\n1. Arithmetic Operators\n2. Assignment Operators\n3. Logical Operators\n4. Comparison (or Relational) Operators\n5. Conditional (or ternary) Operators\n6. String Operators\n7. Bitwise Operators\n\n07.02. Arithmetic Operators\n----------------------\n\n- Arithmetic operators are used to performing arithmetic operations (just like mathematics - calculations) on numbers/the operands\n\nJavaScript supports the following Arithmetic operators (List of Arithmetic operators):\n\n| Operators | Description                           | Example / Result                                |\n| ----------|---------------------------------------|-------------------------------------------------|\n| +         | Addition                              | 10 + 20 = 30 (Sum of num1 and num2)             |\n| -         | Subtraction                           | 20 - 10 = 10 (Difference of num1 and num2)      |\n| *         | Multiplication                        | 10 * 20 = 200 (Product of num1 and num2)        |\n| /         | Division                              | 20 / 10 = 2 (Quotient of num1 and num2)         |\n| %         | Modulus (Division Remainder)          | 20 % 10 = 0 (Remainder of num1 divided by num2) |\n| ++        | Increment                             | var num1 = 100; num1++; Now num1 = 11           |\n| --        | Decrement                             | var num1 = 100; num1--; Now num1 = 9            |\n| **        | Exponentiation (ES2016 / ES6)         | 2 ** 2 = 4 ; 2 ** 3 = 8 (Multiply num1 for num2 times)  |\n| | | |\n\n\u003e **Syntax \u0026 Example**: `07.02.script.js`\n```javascript\n// Arithmetic operators\nvar num1 = 10;\nvar num2 = 4;\n\nalert('Addition ' + (num1 + num2)); // 14\nalert('Subtraction ' + (num1 - num2)); // 6\nalert('Multiplication ' + num1 * num2); // 40\nalert('Division ' + num1 / num2); // 2.5\nalert('Modulus reminder ' + num1 % num2); // 2\nnum1++\nalert('after Increment ' + num1); // 11\nnum2--; \nalert('after Decrement ' + num2); // 3\n\nnum1 = 10;\nnum2 = 4;\nalert('Exponentiation ' + (num1 ** num2)); // (10 ** 4) = 10* 10 * 10 * 10 = 10000\n```\n\n07.03. Assignment Operators\n---------------------\n\n- The Assignment operators are used to assign particular values to variables\n\nJavaScript supports the following Assignment operators (List of Assignment operators):\n\n| Operators | Description                           | Example / Result                      |\n| ----------|---------------------------------------|---------------------------------------|\n| =         | Simple Assignment                     | 10 + 20 = 30; / var total = num1 + num2; (assigns a value to the variable)   |\n| +=        | Add and assign                        | var num1 = 10; num1 += 20; Now num1 = 30 (assigns and adds value to the variable, num1 += 20; is equivalent to num1 = num1 + 20;) |\n| -=        | Subtract and assign                   | var num1 = 10; num1 -= 5; Now num1 = 5 (assigns and subtract value to the variable, num1 -= 5; is equivalent to num1 = num1 - 5;) |\n| *=        | Multiply and assign                   | var num1 = 10; num1 *= 5; Now num1 = 50 (assigns and multiply value to variable, num1 *= 5; is equivalent to num1 = num1 * 5;)    |     \n| /=        | Divide and assign                     | var num1 = 10; num1 /= 5; Now num1 = 2 (assigns and divide value to the variable, num1 /= 5; is equivalent to num1 = num1 / 5;)   |\n| %=        | Modulus and assign                    | var num1 = 10; num1 %= 5; Now num1 = 0 (assigns and Modulus value to the variable, num1 %= 5; is equivalent to num1 = num1 % 5;)  |\n| | | | \n\n\u003e **Syntax \u0026 Example**: `07.03.script.js`\n```javascript\n// Assignment operators\nvar num1 = 10;\nvar num2 = 20\n\n// old methodology\n// num1 = num1 + num2;\n// console.log(num1); // 30\n\n// new techniques\nnum1 += num2; \nconsole.log(num1); // 30\n\n// num2 -= num1; \n// console.log(num2); // 10\n\n// num1 *= num2; \n// console.log(num1); // 200\n\n// num2 /= num1; \n// console.log(num2); // 2\n```\n\n07.04. Logical Operators\n---------------------\n\n- The Logical operators are used to make decisions based on multiple conditions\n- The logical operators are typically used to combine multiple conditional statements and evaluate\n\nJavaScript supports the following Logical operators (List of Logical operators):\n\n| Operators       | Description                           | Example / Result                      |\n| ----------------|---------------------------------------|---------------------------------------|\n| \u0026\u0026              | Logical AND                           | x \u0026\u0026 y; (True if both operands like x and y are true) |\n| \u0026#124;\u0026#124;    | Logical OR                            | x \u0026#124;\u0026#124; y; (True if either x or y is true)|\n| !               | Logical NOT                           | !x; (True if x is not true)           |\n| | | |\n\n\u003e **Syntax \u0026 Example**: `07.04.01.script.js`\n```javascript\n// Logical operators - basic examples\n\n// \u0026\u0026 (Logical AND) - returns true if both operands are true\nconsole.log('true \u0026\u0026 true: ', true \u0026\u0026 true);\nconsole.log('true \u0026\u0026 false: ', true \u0026\u0026 false);\nconsole.log('false \u0026\u0026 true: ', false \u0026\u0026 true);\n\n// ------------------------------\n\n// || (Logical OR) - returns true if one of the operand is true\nconsole.log('true || true: ', true || true);\nconsole.log('true || false: ', true || false);\nconsole.log('false || true: ', false || true);\n\n// ------------------------------\n\n// ! (Logical NOT) True if operand is not true (means I will be true if other is false)\nvar isSeniorCitizen = true;\n\nvar isYoungGeneration = !isSeniorCitizen;\nconsole.log('isYoungGeneration: ', isYoungGeneration);\n```\n\u003chr/\u003e\n\n\u003e **Syntax \u0026 Example**: `07.04.02.script.js`\n```javascript\n// Logical operators - real world scenario/example\n\n// check credit/loan eligibility - (if applicant have HIGH INCOME \u0026 GOOD CREDIT SCORE, he is eligible for credit/loan)\nvar isEarningHighIncome = true;\nvar isGoodCibilScore = false;\nvar isEligibleForLoan;\n\n// check eligibility with \u0026\u0026 Logical AND operator\nisEligibleForLoan = isEarningHighIncome \u0026\u0026 isGoodCibilScore;\nalert('isEligibleForLoan: ' + isEligibleForLoan);\n\n// check eligibility with || Logical OR operator\nisEligibleForLoan = isEarningHighIncome || isGoodCibilScore;\nalert('isEligibleForLoan: ' + isEligibleForLoan);\n\n// ! Logical NOT\nvar isLoanRefused = !isEligibleForLoan;\nalert('isLoanRefused: ' + isLoanRefused);\n```\n\n07.05. Comparison (or Relational) Operators\n---------------------\n07.05. Comparison Operators\n---------------------\n07.05. Relational Operators\n---------------------\n\n- The JavaScript comparison operator compares the two operands\n- It compares two values in a Boolean fashion\n- The comparison operators are used to determine the similarity and difference between different variables\n\nJavaScript supports the following Comparison (or Relational) operators (List of Comparison (or Relational) operators):\n\n| Operators | Description                           | Example / Result                      |\n| ----------|---------------------------------------|---------------------------------------|\n| ==  \u003cbr/\u003e(Loose Equality Operator)      | Is equal to / identical               | x == y    (True if x is equal to y)     |\n| === \u003cbr/\u003e(Strict Equality Operator)      | Eqaul/identical value and identical type| x === y (True if x is equal to y, and they are of the same type) |\n| !=        | Not equal to / different              | x != y (True if x is not equal to y)           |\n| !==       | Not identical    / different value or different type | x !== y )True if x is not equal to y, or they are not of the same type) |\n| \u003c         | Less than                             | x \u003c y (True if x is less than y)|\n| \u003e         | Greater than                          | x \u003e y    (True if x is greater than y)|\n| \u003c=        | Less than or equal to                    | x \u003c= y (True if x is less than or equal to y) |\n| \u003e=        | Greater than or equal to                | x \u003e= y (True if x is greater than or equal to y)|\n| | | |\n\n\u003e **Syntax \u0026 Example**: `07.05.script.js`\n```javascript\n// Comparison (or Relational) operators\nvar num1 = 25;\nvar num2 = 35;\nvar num3 = \"25\";\n \nalert(num1 == num3);  // true\nalert(num1 === num3); // false\nalert(num1 != num2);  // true\nalert(num1 !== num3); // true\nalert(num1 \u003c num2);   // true\nalert(num1 \u003e num2);   // false\nalert(num1 \u003c= num2);  // true\nalert(num1 \u003e= num2);  // false\n```\n\n07.06. Conditional (? or ternary) Operator\n---------------------\n07.06. Conditional Operator\n---------------------\n07.06. Ternary Operator\n---------------------\n\n- Conditional Operator returns a value based on the condition, it is like if-else\n- The conditional (ternary) operator is the only JavaScript operator that takes three operands \n- The conditional operator that assigns a value to a variable based on some condition\n- This operator is frequently used as a shortcut/short-hand method for the if statement\n- **Syntax**: variablename = (condition) ? TRUE value: FALSE value \n\n| Operators | Description                           | Example / Result                      |\n| ----------|---------------------------------------|---------------------------------------|\n| ?         | Ternary operator                      | var result = x \u003c y ? 'x is smaller' : 'y is smaller' (short hand method to write if condition)  |\n| | | |\n\n\u003e **Syntax \u0026 Example**: `07.06.script.js`\n```javascript\n// Conditional (? or ternary) Operator\n\n// age category\nvar currentAge = 100;\nvar category;\n\ncategory = (currentAge \u003c 18) ? 'Minor' : 'Major';\nalert('AGE category: ' + category);\n\n// fees category\nvar isAuthorisedMember = true;\nvar fees;\n\nfees = (isAuthorisedMember == true) ? 5 : 10;\nalert('fees / charges: ' + fees); \n```\n\n07.07. String Operators\n---------------------\n\nVariables can also have string values, `+ operator` can be used to concatenate strings as well as numbers.\n\nThere are two operators which can also be used be for strings:\n\n| Operators | Description                           | Example / Result                      |\n| ----------|---------------------------------------|---------------------------------------|\n| +         | Concatenation                         | string1 + string2 (Concatenation of string1 and string2) |\n| +=        | Concatenation assignment              | string1 += string2 (Appends the str2 to the str1) |\n| | | |\n\n\u003e **Syntax \u0026 Example**: `07.07.script.js`\n```javascript\n// String Operators\nvar message1 = \"Hello\";\nvar message2 = \" World!\";\n \nalert(message1 + message2); // Outputs: Hello World!\n \nmessage1 += message2;\nalert(message1); // Outputs: Hello World!\n```\n\n07.08. Operator precedence\n---------------------\n\n- If an expression has more than one operator, the `execution order is defined by their precedence`, or the implicit priority order of operators\n- Operator precedence determines/describes the way in which operators are parsed with respect to each other / `order in which operations are performed`\n- The operations inside the `parentheses ()` are computed first\n- If many operations have the same precedence (like addition and subtraction), they are `computed from left to right`\n\n\u003e **Syntax \u0026 Example**: `07.08.script.js`\n```javascript\n// Operator precedence\nvar result1 = 10 + 2 * 5\nalert('10 + 2 * 5 =  ' + result1); // answer is 20 NOT 60 (12 * 5 ), actually * or multiplication have higher precedence so the actual calculation is like 10 + ( 2*5 ) = 10 + 10 = 20\n\n// change precedence with `parentheses ()` \nvar result2 = (10 + 2) * 5;\nalert('(10 + 2) * 5 =  ' + result2); // (12) * 5 = 60\n\n// same precedence operators\nvar result3 = 10 + 5 - 2\nalert('10 + 5 - 2 =  ' + result3); // 13 first addition than subtraction\n\nvar result4 = 10 + (5 - 2);\nalert('10 + (5 - 2) =  ' + result4); // 13 first subtraction ie. ( ) than addition\n```\n\nSection 08. Functions\n=====================\n\n08.01. What is a Function?\n---------------------\n\n- A function is basically a `group of statements that perform specific tasks/operations`\n- Functions provide a way to `create reusable code packages` which are more portable and easier to debug\n- Functions allow a programmer to `divide a big program` into a number of/several small and manageable functions\n- It helps programmers in writing `modular codes`\n- The function is a kind of reusable tool where we can write code/functionality to reuse whenever we want (Function allow the code to be called many times without repetition)\n- Wrapping up / making smaller chunks of statements / reusable codes together for readability or separation of concern/proper organization is functions – (Grouping of a repetitive task)\n- Functions (logical block of code) are one of the most important control structure in any programming language\n- In other languages, it might be called `MODULES, SUBROUTINES(SUB-ROUTINES)`\n- There are two steps to utilize function: \n  1. create/define a function with `function` keyword  \n  2. call/invoke a function\n\n\u003e **Note**: \u003cbr/\u003e\nBest Practice - First Define function than call/envoke it!\n\n#### 08.01.01. Here are some advantages of using functions:\n\n- **Code reusability** - call a function several times\n- **Less coding** - makes our program compact, no need to write lines of code each time\n- **Easier to maintain** - changes are done only at one location\n- **Easier to eliminate the errors** - fixing errors becomes much easier\n\n#### 08.01.02. Function Definition / Function Declaration / Creating Function\n\n- The function declaration starts by using the `function keyword`, \n- followed by a `unique function name`, \n- a list of `parameters in parentheses` i.e. () (that might be empty), \n- and a statement block surrounded by `curly braces { }`\n\n\u003e **Syntax \u0026 Example**: `08.01.script.js`\n```javascript\n//1. define / declare / create function\n\nfunction showMessage () {\n  //Body of function \n  //code to be executed\n  console.log('welcome to JavaScript function');\n  alert('welcome to JavaScript function');    \n}\n```\n\n#### 08.01.03. Function Invocation / Calling a Function / Run a Function\n\n- Defined function can be invoked/called/run from anywhere in the document, by typing `function name followed by a set of parentheses, like functionName()`\n\n\u003e **Syntax \u0026 Example**: `08.01.script.js`\n```javascript\n//2. invoke / call the function\n\nshowMessage();\n```\n\n#### 08.01.04. Function Naming\n\nFunction `denotes an action/task`. The function name should be `brief, as accurate as possible and describe` what the function does, like a `verb`.\n\nUsually, Function name starts with:\n\n- \"getSomething\" – returns value,\n- \"createSomething\" – create something,\n- \"calcSomething\" – calculate something,\n- \"checkSomething\" – check something and return a boolean, etc.\n\nExamples of function names:\n- getSum();\n- createFields();\n- calcAge();\n- checkUserType();\n\n08.02. Types of Function\n---------------------\n\n- Regular Function\n- Parameterized Function\n- Return Type Function (Function returning values)\n\n#### 08.02.01. Regular Function\n\n- Simple/Normal function which we use daily to perform some action/task\n\n\u003e **Syntax \u0026 Example**: `08.02.01.script.js`\n```javascript\nvar name = 'Dinanath';\n\n//1. define / declare / create function\nfunction sayHello () {\n  //Body of function \n  //code to be executed\n  console.log('Hello ' + name);\n  alert('Hello ' + name);    \n}\n\n//2. invoke / call the function\nsayHello();\n```\n\n#### 08.02.02.01. Parameterized Function\n\n- One can pass data to functions using parameters (function arguments)\n- You can specify parameters when you define your function to accept input values at run time\n\n\u003e **Syntax \u0026 Example**: `08.02.02.01.script.js`\n```javascript\n// Parameterized function\n//1. define / declare / create function\nfunction sayHello (name) {\n  //Body of function \n  //code to be executed\n  console.log('Hello ' + name);\n  alert('Hello ' + name);    \n}\n\n//2. invoke / call the function\nsayHello('Dinanath');\n\nsayHello('Dino');\n\n// ------------------------------\n\nvar total;\n\nfunction calculateSum (num1, num2) {\n  total = num1 + num2;\n  console.log(total);\n}\n\ncalculateSum(10, 20);\ncalculateSum(100, 200);\n```\n\n#### 08.02.02.02. Default Values for Function Parameters ES6\n\nWith ES6, now you can specify default values to the function parameters. This means that if no arguments are provided to the function when it is called these default parameters values will be used.\n\n\u003e **Syntax \u0026 Example**: `08.02.02.02.script.js`\n```javascript\n// Parameterized function with default parameters\n\n//1. define / declare / create function\nfunction sayHello (name = 'User') {\n  //Body of function \n  //code to be executed\n  console.log('Hello ' + name);\n  alert('Hello ' + name);    \n}\n\n//2. invoke / call the function\nsayHello();\n\nsayHello('Amber');\n\n// ------------------------------\n\nvar total;\n\nfunction calculateSum (num1=1, num2=2) {\n  total = num1 + num2;\n  console.log(total);\n}\n\ncalculateSum();\ncalculateSum(100, 200);\n```\n\n#### 08.02.03. Return Type Function (Function returning values)\n\n- A function can `return a value` back to the script that called the `function, as a result, using the return statement`\n- We can call a function that returns a value and use it in our program\n- The return statement usually placed as the last line of the function\n\n\u003e **Syntax \u0026 Example**: `08.02.03.script.js`\n```javascript\n// Return type function\n//1. define / declare / create function\nfunction getSum (num1, num2) {\n  //Body of function \n  //code to be executed\n  var sum = num1 + num2;\n  return(sum);\n}\n\n//2. invoke / call the function\nconsole.log(getSum(10,20));\nconsole.log(getSum(100,200));\n\nvar total = getSum(50,50);\nalert(total);\n```\n\n08.03. Different ways to define Function\n---------------------\n\nThe syntax that we've used before to create functions is called `function declaration`. There is another syntax for creating a function that is called a `function expression` and `Immediately invoked function expression (IIFE)`\n\n#### 08.03.01. function declaration (Regular/Normal function)\n\n#### 08.03.02. function expression\n\n- Variables contain the expressions of a function\n  - Anonymous function expression\n  - Named function expression\n\n\u003e **Syntax \u0026 Example**: `08.03.02.01.script.js`\n```javascript\n// function declaration (Regular / normal function)\nfunction getSum1(num1, num2) {\n  var total = num1 + num2;\n  return total;\n}\n\n// ------------------------------\n\n// function expression - Anonymus\nvar getSum2 = function(num1, num2) {\n    var total = num1 + num2;\n    return total;\n};\n\nalert(getSum2(10,20));\n\n// ------------------------------\n\n// assign function to another variable\nvar sum1 = getSum2;\nalert(sum1(100,200));\n```\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// function expression - named\nvar getSum2 = function getTotal(num1, num2) {\n  var total = num1 + num2;\n  return total;\n};\n\nalert(getSum2(10,20));\n\n// ------------------------------\n\n// assign function to another variable\nvar sum1 = getSum2;\nalert(sum1(5,10));\n```\n\n#### 08.03.03. Immediately invoked function expression (IIFE)\n\n- It runs as soon as the browser finds it\n- Declare and run the function at the same time\n\n\u003e **Syntax \u0026 Example**: `08.03.03.script.js`\n```javascript\n// Immediately invoked function expression (IIFE)\n(function () {\n  console.log('Welcome to Immediately invoked function expression (IIFE)');\n}());\n\n\n(function(userName) {\n  console.log('Welcome', userName);\n})('Dinanath');\n```\n\n08.04. String Methods and Concatenation\n---------------------\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n\nconst firstName = 'Dinanath';\nconst lastName = 'Jayaswal'\n\nconst fullName = (firstName) + (lastName);\nconsole.log(fullName);\nconsole.log(typeof fullName);\n\n// concatenation\nconsole.log(firstName + ' ' + lastName);\n\nconsole.log('Hello ' + firstName + ' ' + lastName + 'Welcome to JavaScript!');\n\n// append\nlet name1 = 'Dinanath ';\nlet name1 += 'Jayaswal';\nconsole.log(name1);\n\n// concat() method\nconsole.log(firstName.concat(' ', lastName));\n\n// length\nconsole.log(firstName.length);\n\n// change case\nconsole.log(firstName.toLowercase());\nconsole.log(firstName.toUppercase());\n\n// escaping\n// let statement1 = 'wait I'm coming, that's good';\nlet statement1 = \"wait I'm coming, that's good\";\nlet statement2 = 'wait I\\'m coming, that\\'s good';\n\n// string array - get specific character from string like an array\nconsole.log(firstName[0]);\n\n// indexOf\nconsole.log(firstName.indexOf('i'));\nconsole.log(firstName.lastIndexOf('a'));\n\n// charAt()\nconsole.log(firstName.charAt(2));\n\n// get last character from string\nconsole.log(firstName.charAt(firstName.length - 1));\n\n// replace();\nlet replaceString = ('Dinanath', 'DJ');\nconsole.log('My name is:', replaceString); \n\n// substring();\nconsole.log(firstName.substring(0,4));\n\n// slice();\nconsole.log(firstName.slice(0,4));\n\n// slice(); negative number starts from backside\nconsole.log(firstName.slice(-2));\n\n// includes();\nlet message2 = 'Hello Dinanath, welcome to JavaScript';\nconsole.log(message2.includes('Hello'));\nconsole.log(message2.includes('Hi'));\n\n// split()\nlet message2 = 'Hello Dinanath, welcome, to JavaScript';\nconsole.log(message2.split(','));\nconsole.log(message2.split(' '));\n\nlet courses = 'html5, css3, javascript, angular';\nconsole.log(courses.split(','));\n\n```\n\n08.05. Template String\n---------------------\n08.05. Template Literals\n---------------------\n\n- ES6 new feature `Strings Template` offers a convenient way to work with string concatenation/interpolation\n- Template literals provide an easy and clean way to create multi-line strings and perform string interpolation\n- Intuitive expression interpolation for single-line and multi-line strings\n- Use `back-tick (grave accent)` character and `{ var name in curly brace }`, no + plus sign required\n- The best part of Template Literals (Template Strings) is we can `use 'single' \"double\" quotes inside`\n\n- It is part of ES6 but compatible with all the modern browsers and its latest versions\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n\n//old plain javascript approach\nlet user = 'Dinanath';\nlet greetMessage1 = 'Welcome' + ' ' + user + ' ' + 'to JavaScript.';\n\nconsole.log(greetMessage1);\n \nconsole.log('// ------------------------------');\n\nconst firstName = 'Dinanath';\nconst lastName = 'Jayaswal'\nconst course = 'JavaScript'\n\nconst fullName = `Hey ${firstName} ${lastName} Welcome to ${course}.`\n\nconsole.log('// ------------------------------');\n\n//ES6 Template Literals (Template Strings) approach\nlet greetMessage2 = `Hello ${firstName}, How are you?`;\n\nconsole.log(greetMessage2);\n\nconsole.log('// ------------------------------');\n// ------------------------------\n\n//ES6 multi-line string\nlet greetMessage3 = `ES6 Template Literals (Template Strings):\n                    With Template Literals (Template Strings)\n                    we can add multiple lines in string concatenation/interpolation\n`;\n\nconsole.log(greetMessage3);\n\nlet greetMessage4 = ES6 Template Literals (Template Strings):\n                    With Template Literals (Template Strings)\n                    we can add multiple lines in string concatenation/interpolation\n;\n\nconsole.log(greetMessage4);\n```\n\nSection 09. Loops\n=====================  \nSection 09. Loops and Iterations\n=====================\n\n- Loops are used to execute the `same block of code again, with a different value, until a certain condition is met`\n- Loops can execute/repeat a block of code (an action) a number of/several times\n- The basic idea behind a loop is to `automate the repetitive tasks within a program to save time and effort`\n- It makes the `code compact`\n- It is mostly used in array or object (to iterate through series)\n- Loops/iterations is an instruction repeat until a specific condition is reached\n\n### Different Types of Loops in JavaScript:\n\n1. for loop\n2. while loop\n3. do...while loop\n4. for...in loop\n5. for...of loop (ES6)\n6. for...each\n\n09.01. The for loop\n---------------------\n\n- The `For` loop is used to run a piece of code a `set amount of times`\n- Loops through a block of code until the `counter reach a specified number`\n- The for loop `repeats a block of code until a certain condition` is met\n- The for loop is the most simple/compact form of looping\n- For loop consists of 3 statements (), mostly `i = index` is used for loop initialization\n\n\u003e **Syntax \u0026 Example**: `09.01.01.script.js`\n```javascript\n// for loop\n\n/* for (statement 1; statement 2; statement 3) {\n  // Code to be executed\n} */\n\n\n/* for(variable definition/index/initialization; condition checking; increment/decrement expression) {\n  // Code to be executed\n} */\n\nfor (let i=1; i\u003c=5; i++) {\n  alert('Hello, The current index/num is: ' + i);\n  document.write('\u003cli\u003eHello, The current index/num is: ' + i + '\u003c/li\u003e');\n  console.log('Hello, The current index/num is: ' + i);\n}\n```\n\n### 09.01.01. The for loop - Reverse order\n\n\u003e **Syntax \u0026 Example**: `09.01.02.script.js`\n```javascript\n// for loop - reverse order\n\nfor (let i = 5; i \u003e= 1; i--) {\n  alert('Hello, The current index/num is: ' + i);\n  document.write('\u003cli\u003eHello, The current index/num is: ' + i + '\u003c/li\u003e');\n  console.log('Hello, The current index/num is: ' + i);\n}\n```\n\n### 09.01.02. The for loop - Find Even or Odd number\n\n\u003e **Syntax \u0026 Example**: `09.01.03.script.js`\n```javascript\n// for loop - to find out odd even number\n\nfor (let i = 1; i \u003c= 10; i++) {\n  if (i % 2 == 0) {\n    console.log('The current index/num is EVEN : ' + i);\n  } /* else {\n    console.log('The current index/num is ODD : ' + i);\n  } */\n}\n```\n\n09.02. The while loop\n---------------------\n\n- Loops through a block of code until the specified condition evaluates to true\n- In For loop, a variable is part of a loop, but in While loop, we need to declare variable externally\n\n\u003e **Syntax \u0026 Example**: `09.02.01.script.js`\n```javascript\n// while loop\n\n/*while(condition) {\n  // Code to be executed\n}*/\n\nlet i = 1;\n\nwhile (i \u003c= 5) {\n  alert('Hello, The current index/num is: ' + i);\n  document.write('\u003cli\u003eHello, The current index/num is: ' + i + '\u003c/li\u003e');\n  console.log('Hello, The current index/num is: ' + i);\n  i++;\n}\n```\n\n09.03. The do while loop\n---------------------\n09.03. The do...while loop\n---------------------\n\n- The do...while loop is similar to the while loop except that the `condition check happens at the end of the loop`\n- The do...while loop will always be `executed at least once (before checking if the condition is true)`, even if the condition is false\n\n\u003e **Syntax \u0026 Example**: `09.03.01.script.js`\n```javascript\n// do...while loop\n\n/*do {\n    // Code to be executed\n}\nwhile(condition);*/\n\nlet i = 1;\n\ndo {\n  alert('Hello, The current index/num is: ' + i);\n  document.write('\u003cli\u003eHello, The current index/num is: ' + i + '\u003c/li\u003e');\n  console.log('Hello, The current index/num is: ' + i);\n  i++;\n}\nwhile (i \u003c= 5); \n```\n\n09.04. The for in loop\n---------------------\n09.04. The for...in loop\n---------------------\n\n- The for-in loop is a special type of a loop that `iterates over the properties of an object or the elements of an array`\n\n#### 09.04.01. The for...in Loop - array\n\n\u003e **Syntax \u0026 Example**: `09.04.01.script.js`\n```javascript\n// for...in loop\n\n/*for(variable/key in array/object) {\n    // Code to be executed\n}*/\n\n// An array with some elements\nlet arrColors = [\"Red\", \"Green\", \"Blue\", \"Cyan\", \"Magenta\", \"Yellow\", \"Black\"];\n\n// Loop through all the elements in the array \nfor (let color in arrColors) {\n  alert('Color is: ' + arrColors[color]);\n  document.write('\u003cli\u003eColor is: ' + arrColors[color] + '\u003c/li\u003e');\n  console.log('Color is: ' + arrColors[color]);\n}\n```\n\n#### 09.04.02. The for...in Loop - object\n\n\u003e **Syntax \u0026 Example**: `09.04.02.script.js`\n```javascript\n// for...in loop\n\n/*for(variable/key in array/object) {\n    // Code to be executed\n}*/\n\n// An object with some properties \nlet objEmployee = {'emp_name': 'Dinanath', 'emp_addres': 'Mumbai', 'emp_id': '029', 'emp_age':35};\n\n// Loop through all the properties in the object  \nfor (emp in objEmployee) {\n  alert('Employee '+ emp + ' is: ' + objEmployee[emp]);\n  document.write('\u003cli\u003eEmployee '+ emp + ' is: ' + objEmployee[emp] + '\u003c/li\u003e');\n  console.log('Employee '+ emp + ' is: ' + objEmployee[emp]);\n}\n```\n\n#### 09.04.03. The for...in Loop - Inbuilt JavaScript objects\n\n\u003e **Syntax \u0026 Example**: `09.04.03.script.js`\n```javascript\n// for...in loop\n\n/*for(variable/key in array/object) {\n    // Code to be executed\n}*/\n\n// Loop through all the properties in the inbuilt object - window, document, navigator\nfor (props in window) {\n  // alert('document object properties ' + props);\n  document.write('\u003cli\u003edocument object properties ' + props + '\u003c/li\u003e');\n  console.log('document object properties ' + props);\n}\n```\n\n09.05. The for of loop\n---------------------\n09.05. The for...of loop (ES6)\n---------------------\n\n- Loops over `iterable objects such as arrays, strings`, etc.\n- ES6 introduces a new for-of loop which allows us to iterate over arrays or strings very easily\n- The code inside the loop is executed for each element of the iterable object\n\n\u003e **Syntax \u0026 Example**: `09.05.01.script.js`\n```javascript\n// for...of loop\n\n/*for(element in array/string) {\n  // Code to be executed\n} */\n\n// Iterating over an array\nlet arrDays = [\"Monday\", \"TuesDay\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"];\n\nfor (let day of arrDays) {\n  console.log(day);\n  document.write('\u003cli\u003e' + day + '\u003c/li\u003e');\n}\n\n// Iterating over string\nlet name = 'JavaScript';\nfor (let letter of name) {\n  document.write(letter + ',');\n  console.log(letter + ',');\n}\n```\n\n09.06. Break and Continue statement\n---------------------\n\n- `break` and `continue` keywords/statement can change `how the loop behaves`\n- `break` and `continue` keywords can be used in all loops to stop or continue the loop\n- The `break` statement is used to exit a loop early, to \"jump out\" of a loop, stops executing/running a loop\n- The `continue` statement tells the interpreter to immediately start the next iteration of the loop and skip the remaining code block\n\n\u003e **Syntax \u0026 Example**: `09.06.01.script.js`\n```javascript\n// break continue statement\n\n/* break */\nlet arrDays = [\"Monday\", \"TuesDay\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"];\n\nlet i = 1;\nwhile (i \u003c= 10) {\n  if (i == 5) {\n    break;\n  }\n  console.log(i);\n  i++\n}\n\nconsole.log('// ------------------------------');\n\nfor (let i = 0; i \u003c= arrDays.length; i++) {\n  if (i == 3) {\n    break;\n  }\n  console.log(arrDays[i]);\n}\n\nconsole.log('// ------------------------------');\n\n/* continue */\ni = 1;\nwhile (i \u003c= 20) {\n  if (i % 2 == 0) {\n    // console.log('Even Number ', i);\n    i++;\n    continue; // skip rest of the loop body\n\n    i + 100; // non of use \n    console.log('just in even num continue'); // non of use \n  }\n  console.log('Odd Number ', i);\n  i++;\n}\n\nconsole.log('// ------------------------------');\n\nfor (i = 1; i \u003c= 10; i++) {\n  if (i === 5) {\n    continue; // skip rest of the loop body\n    console.log('just after 5 continue...'); // non of use \n  }\n  console.log(i);\n}\n\nconsole.log('// ------------------------------');\n\nfor(let int = 0; int \u003c 10; int++) {\n\n  if(int === 2) {\n    console.log('2 is favorite EVEN number');\n    continue;\n  }\n\n  if(int === 5) {\n    console.log('at 5 stop the loop');\n    break;\n  }\n\n  console.log('current Number is:', int); \n}\n\n```\n\n09.07. for each loop\n---------------------\n09.07. for...each loop\n---------------------\n\n\u003e **Syntax \u0026 Example**: ``\n```javascript\n\nlet arrDays = [\"Monday\", \"TuesDay\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"];\n\narrDays.forEach(function(day)){\n  console.log(day);\n}\n\n```\n\nSection 10. Conditions\n=====================\nSection 10. Conditions - Control Flow\n=====================\n\n- Conditional statements are used to perform different action based on different condition\n- Conditional statements allow the developer to make correct decisions and perform right actions as per condition\n- It helps to perform different actions for different decisions\n- We can use conditional operator to check our condition: \u003e, \u003c, \u003e=, \u003c=, ==, !=, ===\n\n#### We can use the following conditional statements in JavaScript to make decisions:\n\n1. If Statement\n2. If...else Statement\n3. If...else if...else Statement\n4. Switch...Case Statement\n\n10.01. The if statement\n---------------------\n10.01. The if statement and comparison operators\n---------------------\n\n- If the conditional statement is the simplest and basic control statement make decisions and execute statements conditionally\n- The if statement is used to execute a block of code `only if the specified condition evaluates to true`\n- It evaluates the content only `if an expression is true`\n\nIf conditional statements are used to evaluate some kind of condition and do something/perform some actions based on the result\n\n\u003e **Note**: \u003cbr/\u003e\nUse `if` to specify a block of code to be executed, `if a specified condition is true`\n\n\u003e **Syntax \u0026 Example**: `10.01.01.script.js`\n```javascript\n// if conditional statement\n\n/*if(condition/expression) {\n  // Code to be executed if condition/expression is true\n}\n*/\n\nlet user = 'Dinanath';\n\nif (user == 'Dinanath') {\n  console.log('Welcome Dinanath!');\n  window.alert('Welcome Dinanath!');\n}\n\nif (user == 'Dinanath') {\n  console.log('Welcome Authorised User: ' + user + '!');\n  window.alert('Welcome Authorised User: ' + user + '!');\n}\n\n// ------------------------------\n\nlet age = 20;\n\nif (age \u003e= 18) {\n  console.log('MAJOR! Eligible for Voting');\n  window.alert('MAJOR! Eligible for Voting');\n}\n\n// ------------------------------\n\nlet currentHours = 10;\n\nif(currentHours \u003c 12) {\n  console.log('Good Morning!');\n  window.alert('Good Morning!');\n}\n\nif(currentHours \u003e=6 \u0026\u0026 currentHours \u003c 12) {\n  console.log('Good Morning!');\n  window.alert('Good Morning!');\n}\n```\n\n10.02. The if else statement\n---------------------\n10.02. The if...else statement\n---------------------\n\n- The JavaScript `if...else statement` is used to execute the code `weather condition is true or false`\n- The developer can enhance the decision-making capabilities by providing an alternative choice through adding an `else` statement to the `if` statement\n- The condition can be any expression that evaluates to true or false\n- If the condition evaluates to true, statements_1 are executed; otherwise, statements_2 are executed\n\n\u003e **Note**: \u003cbr/\u003e\nUse `else` to specify a block of code to be executed, `if the same condition is false`\n\n\u003e **Syntax \u0026 Example**: `10.02.01.script.js`\n```javascript\n// if...else conditional statement\n\n/*if(condition/expression){  \n// content to be executed if condition is true - statements_1  \n}  \nelse{  \n// content to be executed if condition is false - statements_2\n}*/\n\nlet user = 'Ambar';\n\nif (user == 'Dinanath') {\n  console.log('Welcome Dinanath!');\n  window.alert('Welcome Dinanath!');\n} else {\n  console.log('Welcome Guest!');\n  window.alert('Welcome Guest!');\n}\n\n// ------------------------------\n\nlet age = 15;\n\nif (age \u003e= 18) {\n  console.log('MAJOR! Eligible for Voting');\n  window.alert('MAJOR! Eligible for Voting');\n} else {\n  console.log('MINOR! NOT Eligible for Voting');\n  window.alert('MINOR! NOT Eligible for Voting');\n}\n\n// ------------------------------\n\nlet currentHours = 10;\n\nif(currentHours \u003c 12) {\n  console.log('Good Morning!');\n  window.alert('Good Morning!');\n} else {\n  console.log('Good Evening!');\n  window.alert('Good Evening!');\n}\n```\n\n10.03. The if else if else statement\n---------------------\n10.03. The if...else, if...else statement\n---------------------\n\n- The `if...else if...else` a special statement that is used to `combine multiple if...else statements`\n- It is an advanced form of if...else that allows us to `make a correct decision out of several conditions`\n\n\u003e **Note**: \u003cbr/\u003e\nUse `else if` to specify a new condition to test, `if the first condition is false`\n\n\u003e **Syntax \u0026 Example**: `10.03.01.script.js`\n```javascript\n// If...else if...else conditional statement\n\n/*if(condition/expression 1) {\n    // Code to be executed if condition1 is true statements_1\n} else if(condition/expression 2) {\n    // Code to be executed if the condition1 is false and condition2 is true statements_2\n} else {\n    // Code to be executed if both condition1 and condition2 are false statements_3\n}*/\n\nlet num1 = 200;\nlet num2 = 100;\n\nif (num1 == num2) {\n  console.log('Both numbers are equal');\n} else if (num1 \u003c num2 ) {\n  console.log('Number2 is greater!');\n} else {\n  console.log('Number1 is greater!');\n}\n\n// ------------------------------\n\nlet age = 15; \n\nif (age \u003e= 60) {\n  console.log('SINIOR CIRIZEN!');\n} else if (age \u003c 18) {\n  console.log('MINOR!');\n} else {\n  console.log('MAJOR - Middle Age!');\n}\n\n// ------------------------------\n\nlet currentHours = 15;\n\nif(currentHours \u003e=6 \u0026\u0026 currentHours\u003c 12) {\n  console.log('Good Morning!');\n  window.alert('Good Morning!');\n} else if (currentHours \u003e12 \u0026\u0026 currentHours \u003c=18) {\n  console.log('Good AfterNoon!');\n  window.alert('Good AfterNoon!');\n} else {\n  console.log('Good Evening!');\n  window.alert('Good Evening!');\n}\n```\n\n10.04. The switch case statement\n---------------------\n10.04. The switch...case statement\n---------------------\n\n- The switch...case statement is alternative to an if...else if...else statement, both do almost the same thing\n- This matches the `case` and the `value of condition` and if the case matches, the subsequent block is executed and if none of the case matches `default block` is executed\n- The JavaScript switch statement is used to execute one code from multiple blocks of expressions\n\n\u003e **Note**: \u003cbr/\u003e\nUse `switch` to specify many `alternative blocks of code to be executed`\n\n\u003e **Syntax \u0026 Example**: `10.04.01.script.js`\n```javascript\n// switch...case conditional statement\n\n/* switch(variable/expression){\n  case value1:\n    // Code to be executed if variable/expression === value1\n    break;\n  case value2:\n    // Code to be executed if variable/expression === value2\n    break;\n  default:\n    // Code to be executed if variable/expression is different from all values\n} */\n\nlet grade = 'B'; // A.B,C, or something\n\nswitch (grade) {\n  case 'A':\n    console.log('Great Job! - A Grade');\n    break;\n  case 'B':\n    console.log('Good! - B Grade');\n    break;\n  case 'C':\n    console.log('Congratulations! - Passed');\n    break;\n  default:\n    console.log('Sorry! - Failed...Keep trying!');\n    break;\n}\n\n// ------------------------------\n\nlet sweets = ''; //cake, chocolates, biscuits\n\nswitch (sweets) {\n  case 'chocolates':\n    console.log('Chubby Chocolates!');\n    break;\n  case 'cake':\n    console.log('Happy BirthDay Cake!');\n    break;\n  case 'biscuits':\n    console.log('Enjoy Biscuits!');\n    break;\n  default:\n    console.log('No Sweets! Try some other sweets!');\n    break;\n}\n\n// ------------------------------\n\nconst color = 'red';\n\nswitch(color) {\n  case 'red':\n    console.log('The Dark RED');\n    break;\n  case 'green':\n    console.log('Go Green');\n    break;\n  case 'blue':\n    console.log('Boys are Blue');\n    break;\n  case 'yellow':\n    console.log('Golden Yellow');\n    break;\n  default:\n    console.log('Its some other Color, Enter correct color');\n    break;\n}\n\n// ------------------------------\n\nlet currentDate = new Date();\nlet currentDay;\n\nswitch(currentDate.getDay()) {\n  case 0:\n    currentDay = 'Sunday';\n    break;\n  case 1:\n    currentDay = 'Monday';\n    break;\n  case 2:\n    currentDay = 'Tuesday';\n    break;\n  case 3:\n    currentDay = 'Wednesday';\n    break;\n  case 4:\n    currentDay = 'Thursday';\n    break;\n  case 5:\n    currentDay = 'Friday';\n    break;\n  case 6:\n    currentDay = 'Saturday';\n    break;\n}\n\nconsole.log(`Today is ${currentDay}!`);\n\n```\n\nSection 11. Array\n===================== \n\n11.01. What is an Array?\n---------------------\n\n- An Array is a special type of variable/object which `consists of / stores multiple values`\n- Arrays are complex variables that allow us to store more than one value or a group of values under a single variable name\n- Arrays are defined with `square brackets [ ]` and with `new` keyword\n- Array items are normally separated with `commas,`\n- Arrays are `zero-indexed` i.e. the first element of an array is at index/position 0\n- An array is `ordered collection`, where we have a 0th, 1st, a 2nd, and so on elements\n- Each value (an `element`) in an array has a `numeric position`, known as its `index`, `starts from 0`, so that the first array element position/index is `arr[0]` not arr[1]\n\n#### Different ways to create/define an Array\n\nThere are 3 main ways to construct an array:\n1. By array literal \n2. By creating an instance of Array directly (using the new keyword)\n3. By using an Array constructor (using the new keyword)\n\n11.02. Create Array by array literal\n---------------------\n\n- The simplest way to create an array in JavaScript is enclosing a `comma-separated list of values in square brackets [ ]`\n- var myArray = [element0, element1, ..., elementN];\n\n\u003e **Syntax \u0026 Example**: `11.02.01.script.js`\n```javascript\n// create array with array literal ie. [] square bracket\n\n// var myArray = [element0, element1, ..., elementN];\n\nvar arrColors = ['Red', 'Green', 'Blue', 'Orange'];\nconsole.log(arrColors); // show all elements\n\n// ------------------------------\n\nvar arrCities = ['Delhi', 'Mumbai', 'Kolkota','Bengaluru','Chennai'];\nconsole.log(arrCities[1]); // show 1st index ie. 2nd positioned element\n\n// ------------------------------\n\nvar arrTechnologies = [];\narrTechnologies[0] = 'Java';\narrTechnologies[1] = 'Python';\narrTechnologies[2] = 'C';\nconsole.log(arrTechnologies);\nconsole.log('Total Elements: ' + arrTechnologies.length);\n```\n\n11.03. Create Array by creating an instance of array directly\n---------------------\n11.03. Create Array by creating an instance of array directly (using `new` keyword)\n---------------------\n\n- Array instance can be created using the `new` keyword `new Array()`\n- var myArray = new Array(); OR var myArray = Array();\n\n\u003e **Syntax \u0026 Example**: `11.03.01.script.js`\n```javascript\n// create array with new keyword\n\n// var myArray = new Array();\n\nvar arrColors = new Array();\n\narrColors[0] = 'Red'\narrColors[1] = 'Green'\narrColors[2] = 'Blue'\narrColors[3] = 'Orange'\nconsole.log(arrColors); // show all elements\n\n// read/get array items/elements\nfor (let i = 0; i \u003c arrColors.length; i++) {\n  alert(arrColors[i]);\n}\n\n// ------------------------------\n\nvar arrCities = Array();\narrCities[0] = 'Delhi';\narrCities[1] = 'Mumbai';\narrCities[2] = 'DeKolkotalhi';\narrCities[3] = 'Bengaluru';\narrCities[4] = 'Chennai';\nconsole.log(arrCities); // show all elements\n\n// ------------------------------\n\nvar arrTechnologies = new Array();\n\n// add new array items/elements\nfor (let i = 0; i \u003c= 5; i++) {\n  arrTechnologies[i] = 'JavaScript';\n}\n\nconsole.log(arrTechnologies); // show all elements\n```\n\n11.04. Create Array by using an array constructor\n---------------------\n11.04. Create Array by using an array constructor (using `new` keyword)\n---------------------\n\n- Array instance can be created using the `new` keyword `new Array() passing arguments` in constructor so that we don't have to provide value explicitly\n- var myArray = new Array(element0, element1, ..., elementN);\n\n\u003e **Syntax \u0026 Example**: `11.04.01.script.js`\n```javascript\n// create array with new keyword Array constructor passing parameter\n\n// var myArray = new Array(element0, element1, ..., elementN);\n\nvar arrColors = new Array('Red', 'Green', 'Blue', 'Orange');\nconsole.log(arrColors); // show all elements\n\n// ------------------------------\n\nvar arrCities = new Array('Delhi', 'Mumbai', 'Kolkota','Bengaluru','Chennai');\nconsole.log(arrCities); // show all elements\n\n// ------------------------------\n\nvar arrJsFrameworks = new Array('jQuery','Angular','React','Node','Vue','Express','D3');\nconsole.log(arrJsFrameworks); // show all elements\n```\n\n11.05. Getting the Length of an Array\n---------------------\n\n- The `length` property returns the `length of an array`, `total number of elements` in an array\n- `length` property brings back an `array length - the fixed amount of items` stored in the array\n- The array length is always greater than the index of any of its element `(Array length = last array index + 1)`\n- The maximum length allowed for an array is `4,294,967,295`\n- myarray.length\n\n\u003e **Syntax \u0026 Example**: `11.05.01.script.js`\n```javascript\n// get/retrieve/find array length\n\n// myarray.length\n\nvar arrColors = new Array('Red', 'Green', 'Blue', 'Orange');\nconsole.log(arrColors.length);\n\n// ------------------------------\n\nvar arrCities = new Array('Delhi', 'Mumbai', 'Kolkota','Bengaluru','Chennai');\nconsole.log(arrCities.length);\n\n// ------------------------------\n\nvar arrJsFrameworks = new Array('jQuery','Angular','React','Node','Vue','Express','D3');\nconsole.log(arrJsFrameworks.length);\n```\n\n11.06. Accessing Looping through an Array Elements\n---------------------\n11.06. Loop through an Array Elements\n---------------------\n\n- Array elements can be accessed by their `index using the square bracket notation ie. [index]`\n- Arrays are `zero-indexed` i.e. the first element of an array is at index/position 0\n- An array is `ordered collection`, where we have a 0th, 1st, a 2nd, and so on elements\n- Each value (an `element`) in an array has a `numeric position`, known as its `index`, `starts from 0`, so that the first array element is `arr[0]` not arr[1]\n- One can use `for loop` in coordination with array `length` property to access each element of an array in sequential order\n- myarray[indexNumber], myarray[0] // get first array element\n\n\u003e **Syntax \u0026 Example**: `11.06.01.script.js`\n```javascript\n// access/loop through array element\n\n// myarray[indexNumber], myarray[0]\n\nvar arrColors = new Array('Red', 'Green', 'Blue', 'Orange');\n\nconsole.log(arrColors[0]); // Red\nconsole.log(arrColors[2]); // Blue\n\n// ------------------------------\n\nvar arrCities = new Array('Delhi', 'Mumbai', 'Kolkota', 'Bengaluru', 'Chennai');\nconsole.log(arrCities[1]); // Mumbai\nconsole.log(arrCities[4]); // Chennai\n\n// ------------------------------\n\nvar arrJsFrameworks = new Array('jQuery', 'Angular', 'React', 'Node', 'Vue', 'Express', 'D3');\nconsole.log(arrJsFrameworks[3]); // Node\nconsole.log(arrJsFrameworks[5]); // Express\n\n// Loop through an Array Elements\nfor (let i = 0; i \u003c arrJsFrameworks.length; i++) {\n  document.write('\u003cli\u003e'+arrJsFrameworks[i] + '\u003c/li\u003e');\n}\n```\n\n11.07. Adding Editing an Array Elements\n---------------------\n\n- One can add/edit an array element by simply specifying `array[index] and value` ie. `myarray[5]='value'`\n- If array `index exists it will simply edit` the old value and update the array else it will add an element to the array\n- `push()` method add a new element at the `end of an array`\n- `unshift()` method add a new element at the `beginning of an array`\n- myarray[indexNumber]='value', myarray[2]='value', myarray.push('value'), myarray.unshift('value')\n\n\u003e **Syntax \u0026 Example**: `11.07.01.script.js`\n```javascript\n// add/edit array element\n\n// myarray[indexNumber]='value', myarray[2]='value', myarray.push('value'), myarray.unshift('value')\n\nvar arrColors = new Array('Red', 'Green', 'Blue', 'Orange');\nconsole.log(arrColors);\nconsole.log('arrColors.length: ' + arrColors.length);\n\n// add an element at the end of the array\narrColors.push('Cyan');\nconsole.log(arrColors);\nconsole.log('arrColors.length: ' + arrColors.length);\n\n// add multiple elements at the end of the array\narrColors.push('Magenta','Yellow');\nconsole.log(arrColors);\nconsole.log('arrColors.length: ' + arrColors.length);\n\n// ------------------------------\n\n// add multiple elements at the start of the array\narrColors.unshift('Black','White');\nconsole.log(arrColors);\nconsole.log('arrColors.length: ' + arrColors.length);\n\n// ------------------------------\n\n// edit 1st index ie. 'white' to 'pink'\narrColors[1] = 'pink';\nconsole.log(arrColors);\nconsole.log('arrColors.length: ' + arrColors.length);\n```\n\n11.08. Removing Deleting an Array Elements\n---------------------\n\n- `pop()` method `remove the last element` from an array\n- `shift()` method remove the `first element` from an array\n- myarray.pop(), myarray.shift()\n\n\u003e **Note**: \u003cbr/\u003e\nThe `push() and pop() methods runs faster` than unshift() and shift(). Because push() and pop() methods add and remove elements at the end of an array, therefore, the elements do not move. unshift() and shift() add and remove elements at the beginning of the array that requires re-indexing/re-structuring of the whole array.\n\n\u003e **Syntax \u0026 Example**: `11.08.01.script`\n```javascript\n// remove array element from start and end\n\n// myarray.pop(), myarray.shift()\n\nvar arrColors = new Array('Red', 'Green', 'Blue', 'Orange');\nconsole.log(arrColors);\nconsole.log('arrColors.length: ' + arrColors.length);\n\n// remove an element from the end of the array\narrColors.pop();\nconsole.log(arrColors);\nconsole.log('arrColors.length: ' + arrColors.length);\n\n// ------------------------------\n\n// remove an element from the start of the array\nlet startElement = arrColors.shift();\nconsole.log(startElement);\nconsole.log(arrColors);\nconsole.log('arrColors.length: ' + arrColors.length);\n```\n\n11.09. Array properties and methods\n---------------------\n\n\u003e **Syntax \u0026 Example**: `` \n```javascript\n\n// length\nvar arrColors = new Array('Red', 'Green', 'Blue', 'Orange');\nconsole.log(arrColors.length);\n\n// isArray() - check if array (check the type of variable is array)\nvar arrCities = new Array('Delhi', 'Mumbai', 'Kolkota','Bengaluru','Chennai');\nconsole.log(Array.isArray(arrCities));\nconsole.log(Array.isArray('I am Dinanath'));\n\n// indexOf() - get index/location of provided value\nvar arrJsFrameworks = new Array('jQuery','Angular','React','Node','Vue','Express','D3');\nconsole.log(arrJsFrameworks.indexOf('React'));\n\n// splice values\nconsole.log(arrJsFrameworks.splice(1,3)));\n\n// reverse array\nconsole.log(arrJsFrameworks.reverse()));\n\n// concatenate array\nlet newArray = arrColors.concat(arrCities);\n\n// sort\nlet newSortedColorsArray = arrColors.sort();\nconsole.log(newSortedColorsArray);\nconsole.log(numberArray.sort());\n\n/* exact ascending sort\nlet sortedValues = numberArray.sort(function(num1,num2){\n  return num1 - num2;\n})\n*/\n\n/* exact descending sort\nlet sortedValues = numberArray.sort(function(num1,num2){\n  return num2 - num1;\n})\n*/\n\n// find\nconsole.log(numberArray.find(40));\n\n```\n\nSection 12. Objects\n===================== \n\n12.01. Real Life Objects\n---------------------\n12.01. Object Properties and Method examples\n---------------------\n\n- In real life almost `everything is an object`. \n  - For example: Human, Car, Building, Bike, Pen, Chair, Monitor, Keyboard, Vehicle, Mobile, Computer etc.\n- Let's have a look on some Objects with Properties and Methods:\n\n| Object        | Properties                              | Methods                            |\n|---------------|-----------------------------------------|------------------------------------|\n| Person        | Person.name = 'dinanath'; \u003cbr/\u003e Person.weight = 65; \u003cbr/\u003e Person.color = 'fair' | Person.walk(); \u003cbr/\u003e  Person.talk();  \u003cbr/\u003e Person.eat();   |\n| Bike          | Bike.brand = 'bajaj'; \u003cbr/\u003e Bike.model = 'discover'; \u003cbr/\u003e Bike.color = 'blue'; \u003cbr/\u003e Bike.length = 60; \u003cbr/\u003e Bike.height = 30; \u003cbr/\u003e                                             | Bike.start(); \u003cbr/\u003e Bike.break(); \u003cbr/\u003e Bike.stop();      |\n| Watch         | Watch.type = 'analog'; \u003cbr/\u003e Watch.price = 750; \u003cbr/\u003e                           | Watch.showTime();  \u003cbr/\u003e Watch.setAlarm();        |\n| | | |\n\n\u003e **Note**: \u003cbr/\u003e\nAs a practice think of any other object in your surrounding and list down its Properties and Methods\n\n12.02. What is an Object?\n---------------------\n12.02. What are the Objects?\n---------------------\n\n- JavaScript is an `object-based language` and in JavaScript, almost everything is an object or acts like/as an object\n- An object is a `special/complex` data type that allows you to `store collections of data`\n- An object is a kind of container/declaration where we can group various `data, properties, and behaviors` under one roof (group related variables)\n- A JavaScript object is just a collection of `named values referred to as properties` of the object\n- Objects are defined with `curly braces { }`, the properties of an object are written in pairs (`propertyName: value`)\n- An object contains properties, defined as a `key-value pair` (Objects are a collection of `key-value pair`)\n- A property `key (name) is always a string`, but the value which it stores can be any data types, like strings, numbers, booleans, or complex data types like arrays, function and other objects\n- JavaScript object properties can be accessed through two methods:\n  1. .DOT notation: `object.firstName` \n  2. []Bracket notation: `object['firstName']`\n\n### Different ways to create/define an Object\n\nThere are 3 main ways to construct an object:\n1. By object literal \n2. By creating an `instance` of Object directly (using `new` keyword)\n3. By using an `Object constructor` (using `new` keyword)\n\n12.03. Object literal\n---------------------\n\n- The simplest way to create an object in JavaScript is enclosing a `comma-separated list of properties:values and methods in curly braces { }`\n- var MyObject = { property1: value1, property2: value2.....propertyN: valueN }  \n\n\u003e **Syntax \u0026 Example**:\n```javascript\n// create object with object literal\n  \n// var MyObject = { property1: value1, property2: value2.....propertyN: valueN }\n\n// empty object\nvar HumanObj = {};\n\nconsole.log(HumanObj);\n\nconsole.log('// ------------------------------');\n\n// object with properties\nvar TechnologyObj = { 'name': 'JavaScript', 'version': 6, 'type': 'script', 'isStable': true }\n\nconsole.log(TechnologyObj.name);\nconsole.log(TechnologyObj['isStable']);\n\nconsole.log('// ------------------------------');\n\n// object properly alignment/arranged for readability - with quotes\nvar VehicleObj1 = {\n  'type': 'LWM',\n  'brand': 'Maruti',\n  'model': 'Alto-100',\n  'color': 'White',\n  'isHighEndModel': true,\n  'price': 400000,\n  keyStart: function () {\n    console.log(this.model + ' started!');\n  }\n}\n\nconsole.log(VehicleObj1.brand);\nconsole.log(VehicleObj1['color']);\nVehicleObj1.keyStart();\n\nconsole.log('// ------------------------------');\n\n// object properly alignment/arranged for readability - with quotes\nvar VehicleObj2 = {\n  type: 'LWM',\n  brand: 'Maruti',\n  model: 'Alto-100',\n  color: 'White',\n  isHighEndModel: true,\n  price: 400000,\n  keyStart: function () {\n    alert(this.model + 'started!');\n  }\n}\n\nconsole.log(VehicleObj1.brand);\nconsole.log(VehicleObj1['color']);\nVehicleObj1.keyStart();\n\nconsole.log('// ------------------------------');\n```\n\n12.04. Creating an instance of Object directly\n---------------------\n12.04. Creating an instance of object directly (using the new keyword)\n---------------------\n\n- Array instance can be created using the `new` keyword `new Array() with or without passing arguments/properties-methods` in constructor\n- var MyObject = new Object(); OR var MyObject = Object();\n\n\u003e **Syntax \u0026 Example**:\n```javascript\n// create object with new keyword\n\n// var MyObject = new Object(); OR var MyObject = Object();\n\n// object with properties\nvar TechnologyObj = new Object();\n\nTechnologyObj.name = 'JavaScript';\nTechnologyObj.version = 6;\nTechnologyObj.type = 'script';\nTechnologyObj.isStable = true\n\nconsole.log(TechnologyObj.name);\nconsole.log(TechnologyObj['type']);\n\nconsole.log('// ------------------------------');\n\n// object properly alignment/arranged for readability - with quotes\nvar VehicleObj1 = {\n  'type': 'LWM',\n  'brand': 'Maruti',\n  'model': 'Alto-100',\n  'color': 'red',\n  'isHighEndModel': true,\n  'price': 400000,\n  keyStart: function () {\n    console.log(this.model + ' started!');\n  }\n}\n\n// access property with .DOT notation\nconsole.log(VehicleObj1.brand);\n\n// access property with []Bracket notation\nconsole.log(VehicleObj1['color']);\nVehicleObj1.keyStart();\n\nconsole.log('// ------------------------------');\n\n// object properly alignment/arranged for readability - without quotes\nvar VehicleObj2 = {\n  type: 'LWM',\n  brand: 'Tata',\n  model: 'Safari',\n  color: 'White',\n  isHighEndModel: false,\n  price: 1400000,\n  keyStart: function () {\n    alert(this.model + 'started!');\n  }\n}\n\n// access property with .DOT notation\nconsole.log(VehicleObj2.brand);\n\n// access property with []Bracket notation\nconsole.log(VehicleObj2['color']);\nVehicleObj1.keyStart();\n\nconsole.log('// ------------------------------');\n```\n\n12.05. Object constructor\n---------------------\n12.05. Object constructor (using the new keyword)\n---------------------\n\n- In this method, create a function with arguments \n- Each argument value can be assigned in the current object by using `this` keyword, `this` keyword refers to the `current object`\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// create an object with new keyword - Object constructor with function\n\nfunction Technology(name, version, type) {\n  this.name = name;\n  this.version = version;\n  this.type = type;\n  console.log(this.name);\n  console.log(this.type);\n}\n\nlet JavaScript = new Technology('JavaScript', 6, 'Script Language');\nconsole.log(JavaScript.version);\n\nconsole.log('// ------------------------------');\n\nfunction Vehicle(brand,model,color,price) {\n  this.brand = brand;\n  this.model = model;\n  this.color = color;\n  this.price = price;\n  this.keyStart = function () {\n    console.log(this.model + ' started!');\n  }\n}\n\nvar Maruti = new Vehicle('Maruti','Alto-100','White',400000);\nMaruti.keyStart();\n\nconsole.log('// ------------------------------');\n```\n\n12.06. Accessing objects properties\n---------------------\n12.06. Looping through Objects properties\n---------------------\n\n- To access or get the value of a property, you can use the `dot .`, or `square bracket []` notation\n- We can iterate through the `key-value pairs` of an object using the `for...in loop`\n- MyObject.propertyName; OR MyObject[propertyName]; OR MyObject['propertyName']\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// access/loop thourgh array element\n\n// MyObject.propertyName; OR MyObject[propertyName]; OR MyObject['propertyName']\n\nvar Person = {\n  name:'Dinanath',\n  domain:'IT/Software',\n  gender:'Male',\n  city:'Mumbai',\n  country:'India'\n}\n\nconsole.log(Person.name);\nconsole.log(Person['domain']);\n\nconsole.log('// ------------------------------');\n\n// Loop through an Array Elements\nfor (props in Person) {\n  console.log(Person[props])\n}\n\nconsole.log('// ------------------------------');\n```\n\n12.07. Removing Deleting objects properties\n---------------------\n\n- The `delete` operator can be used to completely remove properties from an object\n- delete MyObject.propertyName;\n\n\u003e **Note**: \u003cbr/\u003e\nThe `delete` operator only removes an `object property or array element`. It does not work/does not affect variables or declared functions.\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// remove/delete Object's Properties\n\n// delete MyObject.propertyName;\n\nvar Person = {\n  name:'Dinanath',\n  domain:'IT/Software',\n  gender:'Male',\n  city:'Mumbai',\n  country:'India'\n}\n\ndelete Person.name\nconsole.log(Person);\nconsole.log(Person.name);\nconsole.log(Person['domain']);\n```\n\n12.08. Manipulating by Value Vs Reference\n---------------------\n\nIn JavaScript we have two categories of types:\n1. Value Types (Primitives = Basic type) - Primitives are copied by their value\n2. Reference Types (Objects = Complex type) - Objects are copied by their Reference/Location in memory\n\n### 1. Value Types (Primitives)\n\n  1. Number\n  2. String\n  3. Boolean\n  4. Undefined\n  5. Null\n  6. Symbol (ES6)\n\n### 2. Reference Types (Objects)\n\n  1. Object\n  2. Function \n  3. Array\n\n\u003e **Syntax \u0026 Example**: \n```\n???\n\n```\n\n12.09. The Window object \n---------------------\n\n- Window Object the global variable/global object `available in the browser environment`, represents the browser window in which the script is running\n- Simply, the window object `represents a window in a browser`\n- The Window interface represents a window containing a DOM (Document Object Model)\n- Window is the object of browser (`The Browser Object Model (BOM)`), it is not the object of javascript\n- The Browser Object Model (BOM) allows JavaScript to \"communicate/talk to\" the browser\n- In `Browser -\u003e Inspect Element -\u003e Console Panel` -\u003e Type `Window`, check different properties and methods available\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n\n// Methods\nwindow.console.log('Console! Hello, Welcome to JavaScript');\n\nwindow.alert('Alert! Hello, Welcome to JavaScript');\n\n// const namePrompt = window.prompt();\nconst namePrompt = window.prompt('Enter Your Name');\nwindow.alert(namePrompt);\n\n\nif(window.confirm('Are you sure?')) {\n  window.console.log('YES - selected');\n} else {\n  window.console.log('NO - clicked');\n}\n\n// Properties\n\n// full/complete browser window height \u0026 width\nouterHeight = window.outerHeight;\nouterWidth = window.outerWidth;\n\nconsole.log('outerHeight -', outerHeight, '::', 'outerWidth -', outerWidth );\n\n// document/page height \u0026 width\n\ninnerHeight = window.innerHeight;\ninnerWidth = window.innerWidth;\n\nconsole.log('innerHeight -', innerHeight, '::', 'innerWidth -', innerWidth );\n\n// scroll position\n\nconsole.log('scrollY', window.scrollY);\nconsole.log('scrollX', window.scrollX);\n\n// location \n\nconsole.log('current window location/url', window.location);\nconsole.log('current window location/url', window.location.href);\n\n// location redirect\n\nwindow.location.href = 'https://www.google.com';\n\n// window location/visited history\n\nwindow.history.go(-1);\n\nlet totalPagesVisitedHistory = window.history.length;\n\n// current browser details - navigator\n\nlet curBrowser = window.navigator.appName; \n//window.navigator.userAgent;\nwindow.navigator.platform;\nwindow.navigator.vendor;\n\n```\n\n12.10. The Math Object\n---------------------\n\n- The Math object allows to perform mathematical tasks\n- Math object provides several constants and methods to perform mathematical operation  (like `min, max, sqrt, pi, round, random`, etc)\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n\nlet pieValue = Math.PI;\n\nconsole.log(Math.E);\nconsole.log(Math.round(2.6));\n\nconsole.log(Math.ceil(2.6));\nconsole.log(Math.floor(2.6));\n\nconsole.log(Math.sqrt(64));\nconsole.log(Math.abs(-10)); //return absolute ie positive number\n\nconsole.log(Math.pow(8,2)); //64\nconsole.log(Math.pow(10,3)); //10 * 10 * 10 = 1000\n\nconsole.log(Math.min(20, 5, 9, 15, 2));\nconsole.log(Math.max(20, 5, 9, 15, 2));\n\nconsole.log(Math.random());\nconsole.log(Math.random() * 20 + 1); // random number till 20\nconsole.log(Math.floor(Math.random() * 20 + 1)); // random number till 20 without any decimals\n\n```\n\n12.11. Date and Time\n=====================\n\n- The Date object is used to deal/work with date and time\n- Simply, the JavaScript date object can be used to get date, day, month and year\n- Date objects are created with `new Date()` - Date constructor can be used to create date object, It provides methods to get and set day, month, year, hour, minute and seconds\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n\nconst today = new Date();\nconsole.log('today is:', today);\n\nconst date1 = new Date('March 29 1980');\nconst date2 = new Date('09-10-1980');\n\nlet currentDate = new Date();\n\nconst currentDateToday = currentDate.getDate();\nconst currentDayToday = currentDate.getDay();\nconst currentMonth = currentDate.getMonth();\nconst currentYear = currentDate.getYear();\nconst currentHours = currentDate.getHours();\nconst currentMinutes = currentDate.getMinutes();\n\nconst newBirthDate = currentDate.setMonth(5);\nconsole.log(newBirthDate);\n\n```\n\nSection 13. Events\n=====================  \n\n13.01. Understanding Events and Event Handlers\n---------------------\n\n- Events are happening/triggering all over, Event lets the developer know `something has occurred/happened`\n- Events occur when the page loads (Onload), when the user interacts with the web page (clicked a link or button/hover) (onlick), pressed key, moved the mouse pointer, mouse-clicked/hover (onmouseover), entered text into an input box or textarea (onchange, onblur, onfocus), submits a form (submit), page unloads (unload)\n- When an event occurs, use a JavaScript `event handler (or an event listener) to detect` them and perform a specific task - Event handlers name always begin with the word `\"on\"`, like onclick, onload, onblur, and so on\n- To react to an event you `listen` for it and supply a `callback function or event handler` which will be called by the browser when the event occurs\n\n13.02. Different Event category\n---------------------\n\nIn general, the events can be categorized into four main groups:\n1. Mouse events\n2. Keyboard events\n3. Form events\n4. Document/Window events\n\n### 13.02.01. Mouse events\n\nA mouse event is triggered when the user clicks some element, move the mouse pointer over an element, etc. Find here some of the important mouse events and their event handler:\n\n- **click** (`onclick` event handler)\n  - Occurs When the `mouse clicks on an element`, links, buttons etc. on a web page \n- **contextmenu** (`oncontextmenu` event handler)\n  - Occurs when a `user clicks the right mouse button` on an element to open a context menu\n- **mouseover / mouseout** (`onmouseover` \u0026  `onmouseout` event handler)\n  - Occurs when the mouse pointer/cursor comes over / leaves (goes outside of) an element\n- **mousedown / mouseup** (`onclick/onmousedown` \u0026 `onmouseup`)\n  - Occurs when the mouse button is pressed/released over an element\n- **mousemove** (`onmousemove` event handler)\n  - Occurs when the mouse pointer/cursor is moved\n\n\u003e **Syntax \u0026 Example**: \n```html\n\u003col class=\"normalList\"\u003e\n  \u003cli\u003e\u003cstrong\u003eclick\u003c/strong\u003e (`onclick` event handler) \u003cbr/\u003e\n    \u003cspan onclick=\"alert('You have clicked an element!')\" style=\"color:blue;cursor: pointer;\"\u003eOccurs When the `mouse clicks on an element`, links, buttons etc. on a web page \u003c/span\u003e\n  \u003c/li\u003e\n  \u003cli\u003e\u003cstrong\u003econtextmenu\u003c/strong\u003e (`oncontextmenu` event handler) \u003cbr/\u003e\n    \u003cspan oncontextmenu=\"alert('You have Right clicked on Me!')\" style=\"color:blue;cursor: pointer;\"\u003eOccurs when a `user clicks the right mouse button` on an element to open a context menu\u003c/span\u003e\n  \u003c/li\u003e\n  \u003cli\u003e\u003cstrong\u003emouseover / mouseout\u003c/strong\u003e (`onmouseover` \u0026  `onmouseout` event handler) \u003cbr/\u003e\n    \u003cspan onmouseover=\"console.log('You have Mouse Over Me!')\" onmouseout=\"console.log('You have Mouse Out Me!')\"  style=\"color:blue;cursor: pointer;\"\u003eOccurs when the mouse pointer/cursor comes over / leaves (goes outside of) an element\u003c/span\u003e\n  \u003c/li\u003e\n  \u003cli\u003e\u003cstrong\u003emousedown / mouseup\u003c/strong\u003e (`onclick/onmousedown` \u0026 `onmouseup`) \u003cbr/\u003e\n    \u003cspan onmousedown=\"console.log('You have clicked on Me!')\" onmouseup=\"console.log('You have released click on Me!')\"style=\"color:blue;cursor: pointer;\"\u003eOccurs when the mouse button is pressed / released over an element\u003c/span\u003e\n  \u003c/li\u003e\n  \u003cli\u003e\u003cstrong\u003emousemove\u003c/strong\u003e (`onmousemove` event handler) \u003cbr/\u003e\n    \u003cspan onmousemove=\"console.log('You Moved mouse over Me!')\" style=\"color:blue;cursor: pointer;\"\u003eOccurs when the mouse pointer/cursor is moved\u003c/span\u003e\n  \u003c/li\u003e\n\u003c/ol\u003e\n\n```\n\n\u003chr/\u003e\n\n\u003e **Syntax \u0026 Example**: `Change background color on mouse movement`\n```js\n\nconst button = document.querySelector('.some-button');\nconst headingText = document.querySelector('h1');\n\nbutton.addEventListener('mousemove', someFunction);\n\nfunction someFunction(evt) {\n  console.log('Event Details:', evt);\n  headingText.innerText = 'Changed after click!';\n\n  document.body.style.backgroundColor = `rgb(${evt.offsetX},${evt.offsetY},40)`\n}\n\n```\n\n### 13.02.02. Keyboard events \n\nA keyboard event is fired up when the user presses or release a key on the keyboard. Here're some of the important keyboard events and their event handler:\n\n- **keydown / keyup** (`onkeydown` \u0026 `onkeyup` event handler)\n  - Occurs when the user presses down a key and then releases the button/a key on the keyboard\n- **keypress** (`onkeypress` event handler)\n  - Occurs when the user presses down a key on the keyboard that has a character value associated with it\n  - Keys like Ctrl, Shift, Alt, Esc, Arrow keys, etc. will not generate a keypress event, but will generate a keydown and keyup event\n\n\u003e **Syntax \u0026 Example**: \n```html\n\u003clabel\u003eEnter Name:\u003c/label\u003e \n\n\u003cinput type=\"text\" placeholder=\"Enter Name\" \nonkeydown=\"console.log('onkeydown pressed a key inside input text!')\" \nonkeyup=\"console.log('onkeyup released a key inside input text!')\" \nonkeypress=\"console.log('onkeypress Other than Ctrl, Shift, Alt, Esc, Arrow keys pressed!')\"/\u003e\n```\n\n\u003chr/\u003e\n\n\u003e **Syntax \u0026 Example**: \n```js\n\nconst nameText = document.querySelector('inputNameText');\nnameText.addEventListener('keypress', nameData);\n\nfunction nameData(evt) {\n  console.log('nameData function called');\n  headingText.innerText = evt.target.value;\n}\n\n```\n\n### 13.02.03. Form events\n\nA form event is triggered when a form control/form fields (text fields/radio buttons/checkbox) receives or loses focus or when the user modifies a form control value by typing text in a text input, select an option in a dropdown/select box, etc. Let us look into some of the most important form events and their event handler:\n\n- **focus** (`onfocus` event handler)\n  - Occurs when the user focuses on an element on a web page, e.g. on an `input` text field\n- **blur** (`onblur` event handler)\n  - Occurs when the user takes the focus away from a form element or a window\n- **change** (`onchange` event handler)\n  - Occurs when the user changes the value of a form element/fields\n- **submit** (`onsubmit` event handler)\n  - Occurs only when the user submits a form on a web page\n\n\u003e **Syntax \u0026 Example**: \n```html\n\u003cform action=\"\" method=\"post\" onsubmit=\"alert('Form data submitted to the server!');\"\u003e\n\n  \u003clabel\u003eFirst Name:\u003c/label\u003e\n  \u003cinput type=\"text\" name=\"first-name\" onfocus=\"showHighlight(this)\" onblur=\"resetHighlight(this)\" required\u003e \u003cbr/\u003e \u003cbr/\u003e\n\n  \u003cselect onchange=\"console.log('You have selected something!');\"\u003e\n      \u003coption\u003eSelect\u003c/option\u003e\n      \u003coption\u003eMale\u003c/option\u003e\n      \u003coption\u003eFemale\u003c/option\u003e\n  \u003c/select\u003e \u003cbr/\u003e \u003cbr/\u003e\n\n  \u003cinput type=\"submit\" value=\"Submit\"\u003e\n  \n\u003c/form\u003e\n\n\n\u003cscript\u003e\n\n  // focus text field\n  function showHighlight(curTxtField) {\n    curTxtField.style.background = \"pink\";\n  }\n\n  function resetHighlight(curTxtField) {\n    curTxtField.style.background = \"white\";\n  }\n\n\u003c/script\u003e\n\n```\n\n\u003chr/\u003e\n\n\u003e **Syntax \u0026 Example**: `Form submit event`\n```js\n\nconst personalDataForm = document.querySelector('form');\npersonalDataForm.addEventListener('submit', submitData);\n\nfunction submitData(evt) {\n  console.log('submitData function called');\n  // to prevent the default behavior of an element - button, link, submit button etc.\n  evt.preventDefault();\n}\n\n```\n\n### 13.02.04. Document/Window events\n\nEvents are happening/triggering all over. Events do trigger even when the page has loaded/unloaded or the user resizes the browser window. Mentioned here some of the most important document/window events and their event handler:\n\n- **DOMContentLoaded** (`DOMContentLoaded` event handler)\n  - Occurs when the HTML is loaded and processed, DOM is fully built\n- **load** (`onload` event handler)\n  - Occurs when web page has finished loading in the web browser\n- **unload** (`onunload` event handler)\n  - Occurs when a user leaves the current web page\n- **resize** (`onresize` event handler)\n  - Occurs when a user resizes the browser window, even when browser window minimized or maximized\n\n\u003e **Note**: \u003cbr/\u003e\nThe unload event is not supported properly in most of the browsers.\n\n\u003e **Syntax \u0026 Example**: \n```html\n\u003cbody onload=\"window.alert('Page loaded successfully!');\" onunload=\"window.alert('sure you want to leave this page?');\"\u003e\n\n\n\u003cscript\u003e\n\n  // resize window\n  window.onresize = resizeWindowSize;\n\n  function resizeWindowSize() {\n    console.log('window.outerWidth ' + window.outerWidth);\n    console.log('window.outerHeight ' + window.outerHeight);\n  }\n  \n\u003c/script\u003e\n```\n\n13.03. Different ways to write the event handler\n---------------------\n\n1. HTML Attribute\n2. DOM element properties (anonymous function)\n3. Registering event listeners (Professional Method (add and remove listeners))\n\n#### 13.03.01. HTML attribute\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n\u003ch2 onclick=\"window.alert('HTML attribute onclick used here!')\" style=\"color:#0000ff; cursor:pointer\"\u003e    13.03.01. HTML attribute | Click Me!\u003c/h2\u003e\n\n\u003cbutton onclick=\"alert('Hello world! Welcome to JavaScript Events!!')\"\u003eClick here...\u003c/button\u003e\n\n\u003cbutton onclick=\"fnShowMessage()\"\u003eInvoke Function\u003c/button\u003e\n\n\n// event handler function\n\nfunction fnShowMessage () {\n  console.log('Welcome to fnShowMessage event handler!');\n  alert('Welcome to fnShowMessage event handler!');\n}\n```\n\n\u003e **Note**: \u003cbr/\u003e\nThis way should be avoided as it makes markup less readable and making it harder to find if there is any bug.\n\n#### 13.03.02. DOM element properties\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n\u003cbutton id=\"messageButton1\"\u003eClick here...\u003c/button\u003e\n\u003cbutton id=\"messageButton2\"\u003eClick here...\u003c/button\u003e\n\n\n// DOM element properties\n\n// method - 1\nmessageButton1.onclick = function () {\n  console.log('Welcome to event handler!');\n  alert('Welcome to event handler!');\n}\n\n// method - 2\ndocument.getElementById(\"messageButton2\").onclick = fnShowMessage;\n\nfunction fnShowMessage() {\n  alert('Hello World! Welcome to JavaScript events');\n}\n```\n\n#### 13.03.03. Registering event listeners\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// myButton.addEventListener('click', someFunc, false);\n\ndocument.querySelector('.clear-button').addEventLister('click', function() {\n  console.log('clear-button clicked');\n})\n```\n\n\u003e **Note**: \u003cbr/\u003e\nThis method is preferred in modern web pages. IE 6-8 do not support this method, there is an alternate for the `addEventListener` is `attachEvent` (myButton.attachEvent (‘onclick', someFunc);)\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n\n???\n\n```\n\n#### 13.03.04. Event Bubbling Delegation\n\n- Event Bubbling = bubbling up the event from bottom to top ie from child to parent element\n- Event Delegation = Event Delegation is exactly the opposite of Event Bubbling. It simply means event passed from top to bottom ie from parent to child element\n\n```html\n\n// create an example of nested element\n\n??? \n\n```\n\nSection 14. DOM (Document Object Model)\n=====================\n\n14.01. What is DOM?\n---------------------\n14.01. What is the Document Object Model?\n---------------------\n\n- DOM represents the whole HTML document, DOM is a structure of HTML web page where all tags are defined in a structured/structural way\n- The Document Object Model (DOM) is the model that describes how all elements in an HTML page (like input fields, images, paragraphs, headings, etc.), are related to the topmost structure: the document itself\n- DOM defines the logical structure of the documents and how they can be accessed and manipulated \n- DOM is a W3C (World Wide Web Consortium) standard which defines a standard for accessing documents like programmers can build documents, navigate their structure, and add, modify, or delete elements and content\n- In DOM world always think in form/terms of `Nodes` (elements, its attributes, text, etc.)\n\n* Structural representation of HTML document (Tree of nodes/elements/tags)\n\n14.02. Node\n---------------------\n\nAs we learned above, in DOM, all parts of the document (like elements, its attributes, text, etc.) are organized in a hierarchical tree-like structure; similar to a real-life family tree that consists of parents and children. In DOM terminology these individual parts of the document are known as `nodes`.\n\nThere are different types of nodes like: `Elements, Attribute \u0026 Text Node`.\n\n\u003e **Syntax \u0026 Example**: \n```html\n\n\u003cul id=\"list\"\u003e --\u003e Element \u0026 Attribute NODE\n  \u003cli\u003efirst item \u003c/li\u003e --\u003e text NODE\n\u003c/ul\u003e\n\n* Elements NODES does not contain text\n\n```\n\n\u003e **Syntax \u0026 Example**: \n`In Browser Window -\u003e Inspect Element (Developer Tools) -\u003e Console: type following and check the output thoroughly`\n\n- `document` - outputs the entire document/current page\n\n- `document.all` - shows HTMLAllCollection(1532) [html, head, meta (html tags)\n\n- `document.url` - displays current url/path\n\n```\nHTMLAllCollection(1532) [html, head, meta, link, link, link, link, link, link, link, link, link, meta, title, meta, link, link, meta, meta, meta, meta, meta, meta, meta, meta, meta,\n```\n\n14.03. JavaScript DOM Selectors\n---------------------\n\nJavaScript is commonly used to find or select, to get or modify the content/value of the HTML elements on the page, and as well as to apply some effects (like show, hide, add events, animate, etc.)\n\nDOM selectors are nothing but methods which helps to pull/traverse/navigate things (elements, nodes)f from the document and do some operations on the same.\n\nLet's learn some of the common ways of selecting the elements on a page and do something using JavaScript.\n\n### 14.03.01. Selecting Elements by ID (`getElementById()`)\n\n- One can select an element based on its `unique ID` with the `getElementById()` method\n- `getElementById()` is the easiest and most common way to find/access an HTML element in the DOM tree\n- `getElementById()` method returns the element having the given id value\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Selecting element with id \nlet mainHeadingElement = document.getElementById('mainHeadingText');\n\n// get html of selected element\nlet mainHeadingHtml = mainHeadingElement.innerHTML;\n\n// get text of selected element\nlet mainHeadingText = mainHeadingElement.innerText;\nalert('mainHeadingHtml: ' + mainHeadingHtml); // text with complete html tags\nalert('mainHeadingText: ' + mainHeadingText); // only text\n\n// console.log('// ------------------------------');\n\n// set text of selected element\nmainHeadingElement.innerHTML = 'This text changed with DOM method...';\n\n// console.log('// ------------------------------');\n\n// set text of another element\nlet subHeadingElement = document.getElementById('subHeadingText');\nsubHeadingElement.innerHTML = mainHeadingElement.innerHTML ;\n\n// console.log('// ------------------------------');\n\n// set css style\nmainHeadingElement.style.backgroundColor = 'pink';\n```\n\n### 14.03.02. Selecting Elements by Class Name (`getElementsByClassName()`)\n\n- `getElementsByClassName()` method is used to select all the `elements having specific class names`\n- `getElementsByClassName()` method `returns an array of all elements` with given class names\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Selecting elements with class\nlet listItems = document.getElementsByClassName(\"list-item\");\nconsole.log(listItems);\n\n// get text of 1st ie 0th element\nlet firstListItemText = listItems[0].innerHTML;\nconsole.log('firstListItemText: ' + firstListItemText);\n\n// console.log('// ------------------------------');\n\n// set text of last element\nlet lastListItem = (listItems.length - 1);\nlistItems[lastListItem].style.color = 'blue';\n\n// console.log('// ------------------------------');\n\n// highlighting all list items through loop\nfor(var listItem in listItems) {  \n  listItems[listItem].style.marginBottom = '10px';\n  listItems[listItem].style.background = '#bbbbbb';\n}\n```\n\n### 14.03.03. Selecting Elements by Tag Name (`getElementsByTagName()`)\n\n- Developer can also `select HTML elements by tag name` using the `getElementsByTagName()` method\n- `getElementsByTagName()` method `returns an array of all elements` with given tag name\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Selecting all LI elements with tag name\nlet liElements = document.getElementsByTagName('li');\nconsole.log(liElements);\n\n// console.log('// ------------------------------');\n\n// get total li tags/elements in page\nlet totalLiElements = liElements.length;\nconsole.log(totalLiElements);\n\n// console.log('// ------------------------------');\n\n// get text of 1st ie 0th li element\nlet firstLiText = liElements[0].innerHTML;\nconsole.log('firstLiText: ' + firstLiText);\n\n// console.log('// ------------------------------');\n\n// set text of last element\nlet lastLi = (liElements.length - 1);\nliElements[lastLi].style.color = 'blue';\n\n// console.log('// ------------------------------');\n\n// highlighting all li elements through loop\nfor(var li in liElements) {  \n  liElements[li].style.marginBottom = '10px';\n  liElements[li].style.background = '#bbbbbb';\n}\n\n// console.log('// ------------------------------');\n```\n\n### 14.03.04. Selecting Elements with CSS Selectors (`querySelectorAll()`)\n\n- `querySelectorAll()` method find `all HTML elements that match a specified CSS selector` (id, class names, types, attributes, values of attributes, etc)\n- CSS selectors provide a very `powerful and efficient way` of selecting HTML elements in a document\n- `querySelectorAll()` method `returns an array` or list of all the elements that matches the specified selectors\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Selecting all ul -\u003e li elements\nlet ulLiElement = document.querySelectorAll('ul li');\nconsole.log(ulLiElement);\n\nlet ulListItemClass = document.querySelectorAll(\"ul li.list-item\")\nconsole.log(ulListItemClass);\n\n// set color of last li element\nulLiElement[ulLiElement.length - 1].style.color = 'red';\n\n// set text of last li element\nulLiElement[ulLiElement.length - 1].innerHTML = 'Dynamic text change at run time';\n```\n\n### 14.03.05. `querySelector` \n\n- selects the single ie first element\n\n```js\n\n???\n\n```\n\n14.04. JavaScript DOM CSS Styling\n---------------------\n\nUsing JavaScript we can also apply CSS style on HTML elements to change the visual look and feel specification/presentation of HTML documents dynamically/at run time. We can apply/set almost all the CSS styles for the elements like fonts, colors, margins, padding, borders, alignments, background images, width and height, position, and so on.\n\n### Naming Conventions of CSS Properties in JavaScript\n- CSS properties like `font-size`, `background-image`, `text-decoration`, etc. contain `hyphens (-)` in names\n- In JavaScript `hyphens (-)` is a reserved operator (a minus sign), so it is impossible to write an expression with `hyphens (-)`, like: elem.style.font-size = '10px';\n- In JavaScript the CSS property names with hyphens are converted to intercapitalized style word (camelCasingNaming)\n- So CSS property `font-size`, `background-color`,`border-left-style` becomes the DOM property `fontSize`, `borderLeftStyle` respectively and so on\n\n### 14.04.01. Applying/Setting Inline Styles on Elements\n- In HTML inline styles are applied directly to the specific HTML element using the `style attribute`, eg. `\u003celement style=\"color:red;\"\u003e`\n- In JavaScript the `style property` is used to get or set the inline style of an element, eg. `elem.style.color = 'red';`\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Selecting element with id \nlet mainHeadingElement = document.getElementById('mainHeadingText');\n\n// set css style\nmainHeadingElement.style.padding = '5px';\nmainHeadingElement.style.backgroundColor = 'pink';\nmainHeadingElement.style.color = 'blue';\nmainHeadingElement.style.border = '5px solid #999999';\n```\n\n### 14.04.02. Retrieving/Getting CSS Styles details from Elements\n- We can get the styles applied on the HTML elements using the `style property`\n- `style property` only returns the style rules set in the element's style attribute, not those applied through internal/embedded style sheets, or external style sheets\n- To get the values of all CSS properties that actually render an element we can use the `window.getComputedStyle()` method\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Selecting element with id \nlet mainHeadingElement = document.getElementById('mainHeadingText');\n\n// set css style\nmainHeadingElement.style.padding = '5px';\nmainHeadingElement.style.backgroundColor = 'pink';\n\n// console.log('// ------------------------------');\n\n// get inline css styles\nconsole.log('mainHeadingElement.style.padding:',mainHeadingElement.style.padding);\nconsole.log('mainHeadingElement.style.backgroundColor:',mainHeadingElement.style.backgroundColor);\n\n// console.log('// ------------------------------');\n\n// get computed style information/ any type of css styles internal/embeded style sheets\nvar cssStyles = window.getComputedStyle(mainHeadingElement);\nconsole.log('internal style - color:',cssStyles.color);\nconsole.log('internal style - border:',cssStyles.border);\n```\n\n### 14.04.03. Applying/Adding CSS Classes to Elements - className\n- We can also get or set CSS classes to the HTML elements using the `className property`\n- As `class` is a reserved word in JavaScript, it uses the `className` property to reference the value of the HTML class attribute\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Selecting element with id \nlet mainHeadingElement = document.getElementById('mainHeadingText');\n\n// remove old classes and apply/set css class\nmainHeadingElement.className = 'bg-color';\n\n// apply/set css class\nmainHeadingElement.className += ' border';\n```\n\n### 14.04.04. Applying/Adding CSS Classes to Elements - classList\n- Using `classList property` is much easier and better to get, set or remove CSS classes from an element\n- `classList property` is supported in all major browsers except Internet Explorer before version 10\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Selecting element with id \nlet mainHeadingElement = document.getElementById('mainHeadingText');\n\n// apply/set/add css class with classList\nmainHeadingElement.classList.add('heading-text');\n\n// apply/set/add css class with classList\nmainHeadingElement.classList.add('border','bg-color');\n\n// remove classes with classList\nmainHeadingElement.classList.remove('border','bg-color');\n\n// if class exists remove it, if not add it\nmainHeadingElement.classList.toggle('heading-text');\n\n// mainHeadingElement.classList.add('border');\n\n// check if class exist and act accordingly\nif(mainHeadingElement.classList.contains('border')) {\n  alert('border class present');\n} else {\n  alert('NO border class present');\n}\n```\n\n14.05. JavaScript DOM HTML get set attributes\n---------------------\n\n- An attribute in HTML `provides extra information` about the element, and it is applied within the start tag\n- An HTML attribute contains two fields: `name \u0026 value / key \u0026 value`\n- JavaScript provides several methods for adding, reading or removing an HTML element's attribute like `setAttribute(), getAttribute(), removeAttribute()`\n\n### 14.05.01. Applying/Setting Attribute on Element\n\n- The `setAttribute()` method is used to set an attribute on the specified element\n- If the attribute already present/exists on the element, the attribute value will be updated; else a new attribute is added with the specified name and value\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Selecting element with id \nlet mainHeadingElement = document.getElementById('mainHeadingText');\nlet clickButtonElement = document.getElementById('clickButton');\nlet linkTextElement = document.getElementById('linkText');\n\n// set attribute class named 'btn'\nmainHeadingElement.setAttribute('class', 'btn');\n\n// set attribute disabled\nclickButtonElement.setAttribute('disabled', '');\n\n// set blank/empty attribute so that it will remove exisiting attribute value\nlinkTextElement.setAttribute('href','');\n```\n\n### 14.05.02. Retrieving/Getting Attribute Value\n\n- The `getAttribute()` method is used to get the current value of an attribute on the element\n- If the specified attribute does not present/exists on the element, it will return `null`\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Selecting element with id \nlet mainHeadingElement = document.getElementById('mainHeadingText');\nlet clickButtonElement = document.getElementById('clickButton');\nlet linkTextElement = document.getElementById('linkText');\n\n// getting the attributes values\nlet getAttrClass = mainHeadingElement.getAttribute('class');\nconsole.log('getAttrClass:', getAttrClass);\n\nlet getAttrDisabled = clickButtonElement.getAttribute('disabled');\nconsole.log('getAttrDisabled:', getAttrDisabled);\n\nlet getAttrHref = linkTextElement.getAttribute('href');\nconsole.log('getAttrHref:', getAttrHref);\n```\n\n### 14.05.03. Removing Attributes from Elements\n\n- The `removeAttribute()` method is used to remove an attribute from the specified element\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n// Selecting element with id \nlet mainHeadingElement = document.getElementById('mainHeadingText');\nlet clickButtonElement = document.getElementById('clickButton');\nlet linkTextElement = document.getElementById('linkText');\n\n// removing the attributes \nmainHeadingElement.removeAttribute('class');\n\n// verify/confirm class removed or not\nconsole.log('mainHeadingElement.getAttribute:', mainHeadingElement.getAttribute('class'));\nconsole.log('mainHeadingElement.classList.contains:', mainHeadingElement.classList.contains('class'));\n\n// console.log('// ------------------------------');\n\nclickButtonElement.removeAttribute('disabled');\n\nlinkTextElement.removeAttribute('href');\n```\n\n### 14.05.04. Selecting document elements without selectors\n### 14.05.04. Select HTMLCollection without selectors\n\n\u003e **Syntax \u0026 Example**: \n```javascript\n\n- document.forms\n  - document.forms[0] or use respective form element index\n  - document.forms[0].id\n  - document.forms[1].method\n  - document.forms[1].action\n\n- document.links\n  - document.links[0]\n  - document.links[0].className //class names as a string\n  - document.links[1].classList[] // collection of classes\n\n- document.images\n  - document.images[0]\n\n- document.scripts\n  - document.scripts[0]\n  - document.scripts[1].getAttribute('src');\n\n```\n\nSection 15. What's Next Step?\n=====================\nGreat Job! Thank You for looking into JavaScript for Beginners. I hope you enjoyed and learned a lot out of it. I think Now you have better understandings of how JavaScript works and functions. To learn more about JavaScript visit [Mozilla JavaScript Reference Guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript). \n- Your Next step could be looking into advanced topics of [HTML5](https://github.com/dinanathsj29/html5-semantic-tags), [CSS3] or [JavaScript]. \n- For detailed view on JavaScript look into [Advanced JavaScript Tutorial], [JavaScript ES6 Tutorial](https://github.com/dinanathsj29/ES6-ECMAScript6-ECMAScript2015-tutorial) or [TypeScript Tutorials](https://github.com/dinanathsj29/typescript-tutorial).\n- You may move forward with any famous and popular JavaScript Frameworks or Libraries like jQuery.js, [Angular](https://github.com/dinanathsj29/angular7-step-by-step), React.js, NPM, Node.js, Vue.js etc. \n\nBest of Luck! Happy Learning!\n\n\n\u003c!--\nLocal and Session Storage \n\n- In `Browser -\u003e Inspect Element -\u003e Console Panel` -\u003e Type `Window`, check different properties and methods available -\u003e localStorage\n\n- In `Browser -\u003e Inspect Element -\u003e Application -\u003e Storage - Local Storage and/or Session Storage\n\n- Local Storage\n\n```js\n\n// set local storage item\n\nlocalStorage.setItem('name', 'Dinanath');\n\n```\n\n- Session Storage\n\n```js\n\n// set session storage item\n\nsessionStorage.setItem('lastName', 'Jayaswal');\n\n```\n\n--\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdinanathsj29%2Fjavascript-beginners-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdinanathsj29%2Fjavascript-beginners-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdinanathsj29%2Fjavascript-beginners-tutorial/lists"}