Friday, August 28, 2020

Learn Shadowing in JavaScript and IIFE- Day 4


 In this articles, we learn about  Shadowing in JavaScript and IIFE.


1.Shadowing in JavaScript 

  • In a programming language, shadowing occurs when a variable is declared in certain scope has the same name defined on its outer scope.
  • In the inner scope, both variables scope overlap.
  • Simply shadowing means an exact copy of anything.


  • So, there are two concepts:

         1.Variable  Shadowing

         2. Function Shadowing

  • Outer variable or function is shadowed by the inner variable or function.
  • Inner variable or function is mask of outer variable or function.


Example:

Program:

Output:



2.IIFE:

  • IIFE stands for Immediately Invoke Function Expression.
  • IIFE is a way to execute functions immediately as soon as they are created.
  • IIFE contains parenthesis ()which are important here, these parenthesis contain expression not a statement.
  •  IIFE has a "function or variable" defined inside IIFE,can not be accessed outside the IIFE  block, thus preventing global scope from getting polluted.


Syntax:

( function () {

// function logic here.

}) ();


Example:

Program:


Output:






Thank you!!!!!!!!!!!!

Monday, August 17, 2020

Learn DataTypes in JavaScript, Typeof Operator and Prototype in JavaScript - Day 3


In this articles, we learn about 
1.DataTypes in JavaScript
2.Typeof operator
3.Prototype in JavaScript


JavaScript  variables can hold three data types: 
1.String
2.Number
3.Boolean


1.String:

    •  String are Primitive data types.
    •  The string data type is used to represent textual data (i.e. sequence of characters).
    •  String are written with quotes, you can use single or double quote.
    •      

    2.Number:

    • The number are Primitive data types.
    • The number represents numeric values.
    • The number data type is used to represent positive or negative numbers  with or without decimal place, or numbers are written using exponential notation.


    3.Boolean:

    • Boolean are Primitive data types.
    • This data type represents the logical entity.
    • Boolean data types can hold only two values: false or true


    Example:

      var z;

      z=100;  //Number

      z="welcome";  //string

    // In above eg. the z holds number as well as string but shows string.


    2.Typeof operator in JavaScript:

    • The typeof operator is a unary operator that is placed before its single operand, which can be any type. 
    • We use typeof operator in javascript to find the data type of the variable.
    • The typeof operator returns the data type of the variable.
    • The operand can be any object, function, or variable.

     Syntax:
                  
                       typeof (operand);


    Example:

    Program:



    Output:






        
                       



                       
       

    3.Prototype in JavaScript :

    • The objects in the JavaScript inherits properties and methods of the prototype.
    • With the help of  prototype you can attach new properties to an object at any time.
    •  There are two ways of creating an object in a prototype.

    1.Literal ways of creating an object.
    2.Constructor way of creating  an object.

    1.Literal way of creating an object.

    Using the literal way of creating objects you can create as well as define the objects in one statement.


    2.Constructor way of creating an object;

    In the constructor way firstly we have to make the function and then we have to create its object.



    program  for both ways: 

     //Literal  way

     


    //Constructor way



    Output:

                           
                                   //Literal way:



    //Constructor way:









    Thank you!!!!!

    Thursday, August 13, 2020

    Learn JavaScript Hoisting, Global Pollution,Undefined and Reference Error-Day 2


    In this articles, we learn  JavaScript Hoisting, Global Pollution, Undefined, and Reference Error.

    1.JavaScript Hoisting:

                                   Hosting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.

    Hoisting is a mechanism in JavaScript that moves the declaration of variables and functions at the top. So, in JavaScript, we can use variables and functions before declaring them.

    JavaScript hoisting is applicable only for declaration, not initialization. It is required to initialize the variables and functions before using their values.


    Example of JavaScript Variable Hoisting:

     Program:

     


    Output:





    Example of JavaScript Function  Hoisting:

    Program:

      

    Output:  

     

     

    2.Global Pollution:

                                  In JavaScript, we have to declare the variables with 'var' keyword, then the variable declared as local if we do not declare variables with var  keyword then the variables become global and this variable  split outside a function so that anyone can modify those variables.

    Without a 'var' keyword, the variable is considered as a global variable and it can be accessed anywhere in the program.

    Example:

    Program:



    Output:



               

    Here, the value of x is not displayed because the variable is declared with the 'var' keyword,i.e called a local variable.


    Output:




     Here, variable x is not declared with the var keyword, i.e called as global pollution.


     3.Undefined:

    JavaScript is interpreted language that means it complies the code line by line.

    Undefined means the variable is declared but not assigned any value then variable returns undefined value.

    If we print one variable before declaring and assigning value then it gives the message is undefined.

    Example:

    Program:


    Output:





     


     4. Reference Error:

    The reference error the object represents an error when a non-existent variable referenced somewhere.


    Example:

    Program:



    Output:










    Thank you!!!!!!

    Function in SQL -part 8

      In this blog we are going to understand  Sql function.   FUNCTION: A function is a database object in SQL Server. It accepts only input pa...