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!!!!!

    No comments:

    Post a Comment

    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...