{"id":687,"date":"2021-12-03T06:56:39","date_gmt":"2021-12-03T06:56:39","guid":{"rendered":"https:\/\/swatilathia.wordpress.com\/?page_id=687"},"modified":"2025-10-05T08:52:51","modified_gmt":"2025-10-05T08:52:51","slug":"javascript-tutorial","status":"publish","type":"page","link":"https:\/\/swatilathia.com\/?page_id=687","title":{"rendered":"JavaScript Tutorial 1"},"content":{"rendered":"<body>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69dd86331663d\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69dd86331663d\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#What_is_JavaScript\" >What is JavaScript?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#Features_of_JavaScript\" >Features of JavaScript<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#Application_of_JavaScript\" >Application of JavaScript<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#JavaScript_Syntax\" >JavaScript Syntax<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#Types_of_JavaScript_Comments\" >Types of JavaScript Comments<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#JavaScript_Variable\" >JavaScript Variable<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#Rules_to_declare_a_JavaScript_variable\" >Rules to declare a JavaScript variable<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#JavaScript_Variable_Scope\" >JavaScript Variable Scope<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#JavaScript_Data_Types\" >JavaScript Data Types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#JavaScript_Operators\" >JavaScript Operators<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#Arithmetic_Operators\" >Arithmetic Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#Comparison_Operators\" >Comparison Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#Logical_Operators\" >Logical Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#Assignment_Operators\" >Assignment Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#Special_Operators\" >Special Operators<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#Conditional_Structure\" >Conditional Structure<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#If_statement\" >If statement<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#If%E2%80%A6else_Statement\" >If\u2026else Statement<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#If%E2%80%A6else_if_else_statement\" >If\u2026else if .. else statement<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#Switch_Case\" >Switch Case<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#JavaScript_Looping_Structure\" >JavaScript Looping Structure<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#While_Loop\" >While Loop<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#The_do%E2%80%A6while_Loop\" >The do\u2026while Loop<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/swatilathia.com\/?page_id=687\/#For_Loop\" >For Loop<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"whatisjs\"><span class=\"ez-toc-section\" id=\"What_is_JavaScript\"><\/span><strong>What is JavaScript?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>JavaScript (js) is a light-weight object-oriented programming language which is used by several websites for scripting the web pages.<\/li>\n\n\n\n<li>It is an interpreter, full-fledged programming language that enables dynamic interactivity on websites when applied to an HTML document.<\/li>\n\n\n\n<li>With JavaScript, users can build modern web applications to interact directly without reloading the page every time.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"features-of-javascript\"><span class=\"ez-toc-section\" id=\"Features_of_JavaScript\"><\/span><strong>Features of JavaScript<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ol style=\"list-style-type:1\" class=\"wp-block-list has-medium-font-size\">\n<li>All popular web browsers support JavaScript as they provide built-in execution environments.<\/li>\n\n\n\n<li>JavaScript follows the syntax and structure of the C programming language.<\/li>\n\n\n\n<li>JavaScript is an object-oriented programming language.<\/li>\n\n\n\n<li>It is a light-weighted and interpreted language.<\/li>\n\n\n\n<li>It is a case-sensitive language.<\/li>\n\n\n\n<li>JavaScript is supportable in several operating systems including, Windows, macOS, etc.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"application-of-javascript\"><span class=\"ez-toc-section\" id=\"Application_of_JavaScript\"><\/span><strong>Application of JavaScript<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"has-medium-font-size\">JavaScript is used to create interactive websites. It is mainly used for:<\/p>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>Client-side validation,<\/li>\n\n\n\n<li>Dynamic drop-down menus,<\/li>\n\n\n\n<li>Displaying date and time,<\/li>\n\n\n\n<li>Displaying pop-up windows and dialog boxes (like an alert dialog box, confirm dialog box and prompt dialog box),<\/li>\n\n\n\n<li>Displaying clocks etc.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"jss\"><span class=\"ez-toc-section\" id=\"JavaScript_Syntax\"><\/span><strong>JavaScript Syntax<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"has-medium-font-size\">JavaScript example is easy to code. JavaScript provides 3 places to put the JavaScript code: within body tag, within head tag and external JavaScript file.<\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;html&gt;  \n\t&lt;body&gt;  \n\t&lt;script type=\"text\/javascript\"&gt;  \n\t\tdocument.write(\"We are learning JavaScript \");  \n\t&lt;\/script&gt;  \n\t&lt;\/body&gt;  \n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>The script tag specifies that we are using JavaScript.<\/li>\n\n\n\n<li class=\"has-medium-font-size\">The text\/javascript is the content type that provides information to the browser about the data.<\/li>\n\n\n\n<li class=\"has-medium-font-size\">The document.write() function is used to display content through JavaScript.<\/li>\n\n\n\n<li>There are 3 places where we can put &lt;script&gt; or JavaScript code:\n<ul class=\"wp-block-list\">\n<li>Body: When page loads, JavaScript runs<\/li>\n\n\n\n<li>Head : When some specific action triggers, JavaScript runs JS (external javascript file): Uses for code re usability<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"comment\"><span class=\"ez-toc-section\" id=\"Types_of_JavaScript_Comments\"><\/span><strong>Types of JavaScript Comments<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>It is a meaningful way to deliver message. There are two types of comments in JavaScript.<\/li>\n\n\n\n<li>Single-line Comment\u00a0 \/\/<\/li>\n\n\n\n<li>Multi-line Comment\u00a0 \/*\u00a0\u00a0 *\/<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"variable_scope\"><span class=\"ez-toc-section\" id=\"JavaScript_Variable\"><\/span><strong>JavaScript Variable<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>A JavaScript variable is simply a name of storage location<\/li>\n\n\n\n<li>There are two types of variables in JavaScript: local variable and global variable<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"rules-to-declare-a-javascript-variable\"><span class=\"ez-toc-section\" id=\"Rules_to_declare_a_JavaScript_variable\"><\/span><strong>Rules to declare a JavaScript variable<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>Name must start with a letter (a to z or A to Z) or underscore.<\/li>\n\n\n\n<li>After first letter we can use digits (0 to 9), for example value1.<\/li>\n\n\n\n<li>JavaScript variables are case sensitive, for example a and A are different variables.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"javascript-variable-scope\"><span class=\"ez-toc-section\" id=\"JavaScript_Variable_Scope\"><\/span><strong>JavaScript Variable Scope<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>The scope of a variable is the region of your program in which it is defined. JavaScript variables have only two scopes.<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list has-medium-font-size\">\n<li><strong>Global Variable<\/strong> \u2212 A global variable has global scope which means it can be defined anywhere in your JavaScript code.<\/li>\n\n\n\n<li><strong>Local Variable<\/strong> \u2212 A local variable will be visible only within a function where it is defined. Function parameters are always local to that function. Within the body of a function, a local variable takes precedence over a global variable with the same name. If you declare a local variable or function parameter with the same name as a global variable, you effectively hide the global variable.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;body&gt;\n\t&lt;script type = \"text\/javascript\"&gt;\n        var a = \"global\";      \/\/ Declare a global variable\n        function fun_scope( ) \n        {\n               \tvar a = \"local\";    \/\/ Declare a local variable\n                document.write(\"The value of a = \",a,\"&lt;br&gt;\");\n        }\n\tfun_scope();\n        document.write(\"The value of a = \",a); \/\/global\n      \t&lt;\/script&gt;     \n&lt;\/body&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\n\t<script type=\"text\/javascript\">\n        var a = \"global\";      \/\/ Declare a global variable\n        function fun_scope( ) \n        {\n               \tvar a = \"local\";    \/\/ Declare a local variable\n                document.write(\"The value of a = \",a,\"<br>\");\n        }\n\tfun_scope();\n        document.write(\"The value of a = \",a); \/\/global\n      \t<\/script>     \n\n\n\n\n<h2 class=\"wp-block-heading\" id=\"data_types\"><span class=\"ez-toc-section\" id=\"JavaScript_Data_Types\"><\/span><strong>JavaScript Data Types<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>JavaScript provides different data types to hold different types of values.<\/li>\n\n\n\n<li>JavaScript has integer, string, Boolean, object, array etc types of values.<\/li>\n\n\n\n<li>JavaScript is a dynamic type language, it means you don\u2019t need to specify type of the variable because it is dynamically used by JavaScript engine.<\/li>\n\n\n\n<li>Use \u201cvar\u201d to specify the data type. It can hold any type of values such as numbers, strings, boolean etc.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>var a=10;\/\/holding number  \nvar b=\"Hello BCA Students\";\/\/holding string  <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"op\"><span class=\"ez-toc-section\" id=\"JavaScript_Operators\"><\/span><strong>JavaScript Operators<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>JavaScript operators are symbols that are used to perform operations on operands.<\/li>\n<\/ul>\n\n\n\n<ol style=\"list-style-type:1\" class=\"wp-block-list has-medium-font-size\">\n<li>Arithmetic Operators<\/li>\n\n\n\n<li>Comparison (Relational) Operators<\/li>\n\n\n\n<li>Logical Operators<\/li>\n\n\n\n<li>Assignment Operators<\/li>\n\n\n\n<li>Special Operators<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"arithmetic-operators\"><span class=\"ez-toc-section\" id=\"Arithmetic_Operators\"><\/span><strong>Arithmetic Operators<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>Arithmetic operators are used to perform arithmetic operations on the operands: +, -, *, \/, %, ++, \u2014<\/li>\n\n\n\n<li>These are addition, subtraction, multiplication, division, modulus, increment &amp; decrement operators.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table has-medium-font-size\"><table><tbody><tr><td>Operator<\/td><td>Description<\/td><\/tr><tr><td>+<\/td><td>Addition<\/td><\/tr><tr><td>\u2013<\/td><td>Subtraction<\/td><\/tr><tr><td>*<\/td><td>Multiplication<\/td><\/tr><tr><td>\/<\/td><td>Division<\/td><\/tr><tr><td>%<\/td><td>Modulus<\/td><\/tr><tr><td>++<\/td><td>Increment<\/td><\/tr><tr><td>\u2014<\/td><td>Decrement<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Arithmetic Operators<\/figcaption><\/figure>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;html&gt;  \n&lt;body&gt;  \n&lt;script type=\"text\/javascript\"&gt;  \n\t\tvar a=20;\n\t\tvar b=10;\n\t\tdocument.write(\"Addition of a+b = \",(a+b),\"&lt;br&gt;\");\n\t\tdocument.write(\"Subtraction of a-b = \",(a-b),\"&lt;br&gt;\");\n\t\tdocument.write(\"Multiplication of a*b = \",(a*b),\"&lt;br&gt;\");\n\t\tdocument.write(\"Multiplication of a\/b = \",(a\/b),\"&lt;br&gt;\");\n\t\tdocument.write(\"Multiplication of a%b = \",(a%b),\"&lt;br&gt;\");\n&lt;\/script&gt;  \n&lt;\/body&gt;  \n&lt;\/html&gt;  <\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n  \n  \n<script type=\"text\/javascript\">  \n\t\tvar a=20;\n\t\tvar b=10;\n\t\tdocument.write(\"<b>Addition of a+b = \",(a+b),\"<br>\");\n\t\tdocument.write(\"Subtraction of a-b = \",(a-b),\"<br>\");\n\t\tdocument.write(\"Multiplication of a*b = \",(a*b),\"<br>\");\n\t\tdocument.write(\"Multiplication of a\/b = \",(a\/b),\"<br>\");\n\t\tdocument.write(\"Multiplication of a%b = \",(a%b),\"<br>\");\n<\/script>  \n  \n\n\n\n\n<h3 class=\"wp-block-heading\" id=\"comparison-operators\"><span class=\"ez-toc-section\" id=\"Comparison_Operators\"><\/span><strong>Comparison Operators<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>Arithmetic operators are used to perform arithmetic operations on the operands: &lt;, &gt;, &lt;=, &gt;=, ==, ===, !=, !==<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table has-medium-font-size\"><table><tbody><tr><td>Operator<\/td><td>Description<\/td><\/tr><tr><td>==<\/td><td>Is equal to<\/td><\/tr><tr><td>===<\/td><td>Identical (equal &amp; of same type)<\/td><\/tr><tr><td>!=<\/td><td>Not equal<\/td><\/tr><tr><td>!==<\/td><td>Not identical<\/td><\/tr><tr><td>&gt;<\/td><td>Greater than<\/td><\/tr><tr><td>&gt;=<\/td><td>Greater than or equal to<\/td><\/tr><tr><td>&lt;<\/td><td>Less than<\/td><\/tr><tr><td>&lt;=<\/td><td>Less than or equal to<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Comparision Operators<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"logical-operators\"><span class=\"ez-toc-section\" id=\"Logical_Operators\"><\/span><strong>Logical Operators<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-table has-medium-font-size\"><table><tbody><tr><td>Operator<\/td><td>Description<\/td><\/tr><tr><td>&amp;&amp;<\/td><td>Logical AND<\/td><\/tr><tr><td>||<\/td><td>Logical OR<\/td><\/tr><tr><td>!<\/td><td>Logical NOT<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Logical Operators<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"assignment-operators\"><span class=\"ez-toc-section\" id=\"Assignment_Operators\"><\/span><strong>Assignment Operators<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-table has-medium-font-size\"><table><tbody><tr><td>Operator<\/td><td>Description<\/td><\/tr><tr><td>=<\/td><td>Assign<\/td><\/tr><tr><td>+=<\/td><td>Add &amp; assign<\/td><\/tr><tr><td>-=<\/td><td>Subtract &amp; assign<\/td><\/tr><tr><td>*=<\/td><td>Multiply &amp; assign<\/td><\/tr><tr><td>\/=<\/td><td>Divide &amp; assign<\/td><\/tr><tr><td>%=<\/td><td>Modulus &amp; assign<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Assignment Operators<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"special-operators\"><span class=\"ez-toc-section\" id=\"Special_Operators\"><\/span><strong>Special Operators<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-table has-medium-font-size\"><table><tbody><tr><td>Operator<\/td><td>Descritption<\/td><\/tr><tr><td>? :<\/td><td>Conditional operator returns value based on the condition, like If..else<\/td><\/tr><tr><td>,<\/td><td>Comma operator allows multiple expressions to be evaluated as single statement<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Special Operators<\/figcaption><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Example<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;script type='text\/javascript'&gt;\n\tvar a=200;\n\tvar b=100;\n\tc=(a&gt;b)?\"a is bigger\":\"b is bigger\";\n\tdocument.write(c);\t\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n<script type=\"text\/javascript\">\n\tvar a=200;\n\tvar b=100;\n\tc=(a>b)?\"a is bigger\":\"b is bigger\";\n\tdocument.write(c);\t\n<\/script>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"js_cond\"><span class=\"ez-toc-section\" id=\"Conditional_Structure\"><\/span><strong>Conditional Structure<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>The JavaScript if-else statement is used to execute the code whether condition is true or false.<\/li>\n\n\n\n<li>In JavaScript, there are three form of if statement.<\/li>\n<\/ul>\n\n\n\n<ol style=\"list-style-type:1\" class=\"wp-block-list has-medium-font-size\">\n<li>If Statement<\/li>\n\n\n\n<li>If else statement<\/li>\n\n\n\n<li>if else if statement<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"if-statement\"><span class=\"ez-toc-section\" id=\"If_statement\"><\/span><strong>If statement<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>It evaluates the content only if expression is true.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>if(expression)\n{  \n\/\/content to be evaluated  \n}  <\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;script language=\"javascript\"&gt;  \nvar a=11;  \nif(a&gt;10)\n{  \n      document.write(\"a is greater than 10\");  \n}  \n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p><strong>Example<\/strong><\/p>\n\n\n\n<script language=\"javascript\">  \nvar a=11;  \nif(a>10)\n{  \n      document.write(\"a is greater than 10\");  \n}  \n<\/script>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"if-else-statement\"><span class=\"ez-toc-section\" id=\"If%E2%80%A6else_Statement\"><\/span><strong>If\u2026else Statement<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>It evaluates the content whether condition is true of false.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>if(expression)\n{  \n\/\/content to be evaluated if condition is true  \n}  \nelse\n{  \n\/\/content to be evaluated if condition is false  \n}  <\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;script&gt;  \nvar a=20;  \nif(a%2==0)\n{ \n\tdocument.write(a,\" is even number\");  \n}  \nelse\n{  \n        document.write(a,\" is odd number\");  \n}  \n&lt;\/script&gt;  <\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n<script>  \nvar a=20;  \nif(a%2==0)\n{ \n\tdocument.write(a,\" is even number\");  \n}  \nelse\n{  \ndocument.write(a,\" is odd number\");  \n}  \n<\/script>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"if-else-if-statement\"><span class=\"ez-toc-section\" id=\"If%E2%80%A6else_if_else_statement\"><\/span><strong>If\u2026else if .. else statement<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>It evaluates the content only if expression is true from several expressions.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>if(expression1){  \n\/\/content to be evaluated if expression1 is true  \n}  \nelse if(expression2){  \n\/\/content to be evaluated if expression2 is true  \n}  \nelse if(expression3){  \n\/\/content to be evaluated if expression3 is true  \n}  \nelse{  \n\/\/content to be evaluated if no expression is true  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;script&gt;  \nvar a=20;  \nif(a==10)\n{  \t\t\ndocument.write(\"a is equal to 10\");  \n}  \nelse if(a==15)\n{  \ndocument.write(\"a is equal to 15\");  \n}  \nelse if(a==20)\n{  \ndocument.write(\"a is equal to 20\");  \n}  \nelse\n{  \ndocument.write(\"a is not equal to 10, 15 or 20\");  \n}  \n&lt;\/script&gt;    \t<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n<script>  \nvar a=20;  \nif(a==10){  \t\t\ndocument.write(\"<b>a is equal to 10\");  \n}  \nelse if(a==15){  \ndocument.write(\"<b>a is equal to 15\");  \n}  \nelse if(a==20){  \ndocument.write(\"<b>a is equal to 20\");  \n}  \nelse{  \ndocument.write(\"<b>a is not equal to 10, 15 or 20\");  \n}  \n<\/script>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"switch-case\"><span class=\"ez-toc-section\" id=\"Switch_Case\"><\/span><strong>Switch<\/strong> <strong>Case<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>The JavaScript switch statement is used to execute one code from multiple expressions. <\/li>\n\n\n\n<li>It is just like else if statement. But it is convenient than if..else..if because it can be used with numbers, characters etc. <\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>switch(expression){  \ncase value1:  \n code to be executed;  \n break;  \ncase value2:  \n code to be executed;  \n break;  \n......  \n  \tdefault:   \n code to be executed if above values are not matched;  \n}<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;script&gt;  \nvar grade='B';  \nvar result;  \nswitch(grade)\n{  \n   case 'A':  \n            result=\"You have got A Grade\";  \n            break;  \n   case 'B':  \n            result=\"You have got B Grade\";  \n            break;  \n   case 'C':  \n            result=\"You have got C Grade\";  \n            break;  \n   default:  \n            result=\"You haven't got any Grade\";  \n}  \ndocument.write(result);  \n&lt;\/script&gt;  <\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n<script>  \nvar grade='B';  \nvar result;  \nswitch(grade)\n{  \n   case 'A':  \n            result=\"You have got A Grade\";  \n            break;  \n   case 'B':  \n            result=\"You have got B Grade\";  \n            break;  \n   case 'C':  \n            result=\"You have got C Grade\";  \n            break;  \n   default:  \n            result=\"You haven't got any Grade\";  \n}  \ndocument.write(\"<b>\",result);  \n<\/script>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>Use break statement in a switch case block, otherwise once a case block is executed, the rest of the subsequent case blocks will execute. <\/li>\n\n\n\n<li>In above example, if we skip to write break in every case, the output will be: <strong>You have got B Grade You have got C Grade You haven\u2019t got any Grade<\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"js_loop\"><span class=\"ez-toc-section\" id=\"JavaScript_Looping_Structure\"><\/span><strong>JavaScript Looping Structure<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>It may happen that during the programming one may need to perform some kind of action over and over again. <\/li>\n\n\n\n<li>In such situations, you would need to write loop statements to reduce the number of lines.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"While_Loop\"><\/span><strong>While Loop<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>The purpose of a while loop is to execute a statement or code block repeatedly as long as an expression is true. Once the expression becomes false, the loop terminates.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>while (expression) {\n   \t\tStatement(s) to be executed if expression is true\n}<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;script type = \"text\/javascript\"&gt;\n   var start = 1;\n   document.write(\"&lt;b&gt;Loop has started from 1 &amp; ended upto 10\");\n   while (start &lt;= 10) \n   {\n          document.write(\"&lt;b&gt;Loop Number : \" + start + \"&lt;br&gt;\");\n          start++;\n   }\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n<script type=\"text\/javascript\">\n       \t    var start = 1;\n            document.write(\"<b>Loop has started from 1 & ended upto 10<br>\");\n            while (start <= 10) {\n               document.write(\"<b>Loop Number : \" + start + \"<br>\");\n               start++;\n            }\n<\/script>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"the-do-while-loop\"><span class=\"ez-toc-section\" id=\"The_do%E2%80%A6while_Loop\"><\/span><strong>The do\u2026while Loop<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>The do\u2026while loop is similar to the while loop except that the condition is checked the end of the loop. <\/li>\n\n\n\n<li>This means that the loop will always be executed at least once, even if the condition is false.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>do {\n   Statement(s) to be executed;\n} while (expression);<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;script type = \"text\/javascript\"&gt;\n       var start = 0;\n       do \n       {\n             document.write(\"Loop Number : \" + start + \"&lt;br&gt;\");\n             start++;\n       }while (start &lt; 5);\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>In above example, the condition is true. <\/li>\n\n\n\n<li>We will have one more example with false condition. In this example, it will execute the loop once. As it checks the condition at the time of exit, it will not execute the loop second time.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Example<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;script type = \"text\/javascript\"&gt;\n       var start = 1;\n       do \n       {\n             document.write(\"&lt;b&gt;Loop Number : \" + start + \"&lt;br&gt;\");\n             start++;\n       }while (start &gt; 5);\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n<script type=\"text\/javascript\">\n       var start = 1;\n       do \n       {\n             document.write(\"<b>Loop Number : \" + start + \"<br>\");\n             start++;\n       }while (start > 5);\n<\/script>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"For_Loop\"><\/span><strong>For Loop<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li>The \u2018for\u2019 loop is the most compact form of looping. It includes the following three important parts:<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list has-medium-font-size\">\n<li><strong>The loop initialization<\/strong>: where we initialize our counter to a starting value. The initialization statement is executed before the loop begins.<\/li>\n\n\n\n<li><strong>The test statement:<\/strong> which will test if a given condition is true or not. If the condition is true, then the code given inside the loop will be executed, otherwise the control will come out of the loop.<\/li>\n\n\n\n<li><strong>The iteration statement:<\/strong> where you can increase or decrease your counter.<\/li>\n\n\n\n<li>You can put all the three parts in a single line separated by semicolons.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>for (initialization; test condition; iteration statement) {\n   Statement(s) to be executed if test condition is true\n}<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;script type=\"text\/javascript\"&gt;  \n\t\ta=parseInt(prompt(\"Enter start value\"));\n\t\tb=parseInt(prompt(\"Enter end value\"));\n\t\tfor(n=a;n&lt;=b;n++)      \n\t\t{\n\t\t\tdocument.write(\"&lt;b&gt;\",n,\"&lt;br&gt;\");\n\t\t}\n&lt;\/script&gt; <\/code><\/pre>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>What is JavaScript? Features of JavaScript Application of JavaScript JavaScript is used to create interactive websites. It is mainly used for: JavaScript Syntax JavaScript example is easy to code. JavaScript provides 3 places to put the JavaScript code: within body tag, within head tag and external JavaScript file. Types of JavaScript Comments JavaScript Variable Rules [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"om_disable_all_campaigns":false,"footnotes":""},"class_list":["post-687","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/swatilathia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=687"}],"version-history":[{"count":5,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/687\/revisions"}],"predecessor-version":[{"id":5611,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/687\/revisions\/5611"}],"wp:attachment":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}