JavaScript

JavaScript – Introduction

JavaScript Introduction: We can Write JavaScript code in places of HTML document We can Write JavaScript code in places of HTML document Body Location: Execute Script when web page is loading. <html>            <body>                        <script>                                    alert(“Alert box while loading page”);                        </script>            </body></html> Head Location: Execute Script on action (for example click on button). <html>            <head>                        <script>                                    …

JavaScript – Introduction Read More »

JavaScript – Comments

Comments: Comments are used to describe the code or document. These are 2 types Single line Comment: It is represented by double forward slashes (//). <!doctype html><html>            <body>                        <script>                                     var a=10;                                     var b=20;                                     var c=a+b; // + operator add values of a & b and store result into c                                     document.write(c); // write() – display information …

JavaScript – Comments Read More »

JavaScript – Variables

Variable: Syntax: Example: var identity;   orlet identity; var name = “amar”;var age = 23;var salary = 35000.00; Rules to create variable: Variable Declaration, Assignment, Modify and Initialization: Declaration: A variable without value is called declaration var a;     let b; Assignment: Assigning value to variable which is already declared. var a;  // declarationa = 10;  // assignment …

JavaScript – Variables Read More »

JavaScript – Functions

Function: Syntax: Example:       function identity()      {             …..             Logic             …..      }        function add()       {            var a=10, b=20;            var c = a+b;            print(c);       } Note: We always perform operations when action performed. For example, display alert message when user clicks on button <html>            <head>                        <script>                                    function clickMe()                                    {                                                alert(“Hello”);                                    }                        </script>            </head>            <body>                        <h2> JavaScript …

JavaScript – Functions Read More »

Functions – Classification

Classifications: Depends on taking input parameters and return values, functions classified into four types. No Parameters &No Return values With Parameters &No Return values With Parameters &With Return values No Parameters &With Return values function say(){            write(“Hello”);} function add(a, b){            var c = a+b;            write(c);} function add(a, b){            var c = a+b;            return c;} function …

Functions – Classification Read More »

JavaScript – Call By Value and Call By Reference

Call By Value: <html>            <body>                        <p id=”demo”></p>                                    <script>                                                function modify(y)                                                {                                                            y=y+10;                                                            document.write(“y inside function : ” + y);                                                }                                                var x = 10 ;                                                modify(x);                                                document.getElementById(“demo”).innerHTML = x;                                    </script>            </body></html> Call By Reference: <html>            <body>                        <p id=”demo”></p>                                    <script>                                                function modify(x)                                                {                                                            x[0]=x[0]+10;                                                            document.write(“x[0] inside function : ” + x[0]);                                                }                                                var arr = [10, …

JavaScript – Call By Value and Call By Reference Read More »

JavaScript – Higher Functions

Explain Higher Order Functions in JavaScript: Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions. Function takes function as argument: <html>            <body>                        <script>                                    function abc() {                                                document.write(“Hello world”)                                    }                                    function higherOrder(xyz) {                                                xyz();                                    }                                    higherOrder(abc);                        </script>            </body></html> Function returning function: <html>            <body>                        <script>                                    function …

JavaScript – Higher Functions Read More »

JavaScript – Local and Global Variables

Local variables: <html>            <head>                        <script>                                    function add(){                                                var a=10;                                                var b=20;                                                var c=a+b;                                                document.write(“Sum is : ” + c);                                    }                        </script>            </head>            <body>                        <button onclick=”add()”>add</button>            </body></html> Global variables: Defining variables outside to all functions – we can them from all functions. <html>            <head>                        <script>                                    var a=5;                                    var b=3;                                    function add(){                                                document.write(“Sum is : ” + …

JavaScript – Local and Global Variables Read More »

JavaScript – Var, Let and ConstJavaScript

Var Let Const Variable can be either Global Scope or Local Scope Variable is Local scope Variable is Local Scope Re-Declaration or Updating of variable is possible Only Updating possible Nothing is possible. Hoisting allowed – Variables initializes with “undefined” Hoisting allowed – Variables not initializes with values. Hoisting allowed – Variables not initializes with …

JavaScript – Var, Let and ConstJavaScript Read More »

Scroll to Top