Thursday, 15 July 2021

Operators in JavaScript #5 | JavaScript Operators in one video @echocoding | soham kawde

 


code source  JavaScript Operators

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Operator</title>
</head>
<body>
    <script>
        // Arithmetic operators
        var x = 5 +4;  console.log('add '+x);
        var y = 5-4; console.log('substract '+y);
        var z = 5*4; console.log('multiply '+z);
        var r = 20/2; console.log('divide '+r);
        var modulus = 25%2; console.log('modulus' + modulus);
        var exponentiation = 2**3; console.log('exponentiation '+ exponentiation);
        // Assignment operators
       var add = 5;
       add +=4// add = 4+5;
       console.log(add);
       var sub = 5;
       sub -=4// substract = 5-4
       console.log(sub);
       var multiply = 4;
       multiply *=5//multiply = 4*5
       console.log(multiply);
       var divide = 20;
       divide /=2//divide = 20/2
       console.log(divide);
       var modulus = 25;
       modulus %=2// modulus = 25 % 2
       console.log(modulus);
       var exponentiation = 2;
       exponentiation **= 3// exponentiation =  2**3
       console.log(exponentiation);

       // string operators
       var one = "hello program";
       var end = "end program";
       console.log(one +' '+ end);
       console.log(one += " " + end);

    // Comparison operators
    var first  = 1;
    var second = '1';
        console.log(first == second); // equal to 
        console.log(first === second); // equal to and eqaul type
    
    var third = 3;
    var fourth = 4;
    console.log(third != fourth);// not equal to 
    console.log(third !== fourth);// not equal to or not equal type
    console.log(3>4);//Greater than
    console.log(3<4);//less than

    var numone = 2;
    var numtwo = 3;
    console.log(numone >= numtwo); // Greater than or equal to
    console.log(numone <= numtwo); // less than or equal to

    var numone = 2;
    var numtwo = 2;
    console.log(numone >= numtwo); // Greater than or equal to
    console.log(numone <= numtwo); // less than or equal to
    
        // logical operators
        var fisrtone = 1;
        var secondone = 2;
        var thirdone = 1;
        var fourthone = 2;

        console.log(fisrtone == thirdone && secondone == fourthone); // && and operator
        
        var fisrtone = 1;
        var secondone = 2;
        var thirdone = 1;
        var fourthone = 2;

        console.log(fisrtone == fourthone || secondone == thirdone); // || Or operator
        
        console.log(fisrtone != fourthone || secondone != thirdone); // ! NOt operator
        console.log(fisrtone != fourthone && secondone != thirdone); // ! NOt operator
    </script>
</body>
</html>

timestamps: Arithmetic operators 00.01 Assignment operators 06.02 string operators 12.01 Comparison operators 14.32 logical operators 21.08 JavaScript Operators JavaScript Arithmetic Operators :- It is used to perform arithmetic operation on numbers and variables. Addition arithmetic operators (+) : With this operator programmer can add two values ; var a = 4+5; console.log(a); //Output : 9 Subtraction arithmetic operators ( - ) : With this operator programmer can subtract two values. var a = 5-4; console.log(a) // Output : 1 Multiplication arithmetic operators (*): this help a programmer to multiply two values; var a = 4*5; console.log(a) // Output: 20 Exponentiation arithmetic operators (**):By using this programmer can get output in Exponentiation form (23 ). Modulus (Division Remainder) arithmetic operators (%) : with this programmer divide two values and get remainder in the result. Increment arithmetic operators (++): this operator increase value by adding value 1 in existing value. Decrement arithmetic operators(--) this operator decrease value by adding value 1 in existing value. JavaScript Assignment Operators It assign value to left side varible or number from the right side variable or number on given condition. = assign operator : this assign right value to left side values or variables. += this operator add right side value to left side value. -= this operator substract right side value from left side value. *= this operator multiply right side value to left side value. /= this operator divided left side value from right side value. %= this operator give remainder by divided left side value from right side value. **= this operator give exponentiation result in the form of 23 . JavaScript string operator this helps to cancatenate (add) strigns. Adding string to number return string Javascript comparison operators If programmer wants to compare two or more than two values than comparison operator is used. If check both values and datatype. Equal to (==) It will return true if condition equal in value. Not equal (!=) it will return true if condition is not equal in values. Equal values and Equal datatype (===) it will return true if conditionn is equal both in values and datatype. Not equal values or not equal datatype (!==) it will return true if condition is not equal in values or datatypes terms. Greater than It will return true if first first variable or values is greater than second variable or values. Less than It will return true if first values or variable is less than second variable or values. Greater than or Equal to this will return true if first variable or value is greater than or Equal to second variable or values. Less than or Equal to this will return true if first variable or values is less than or equal to second variable or values. JavaScript Logical Operators && Logical and : this operator return true if each and every given condition is true. || logical or : this operator return true if any one of given condition is true. ! logical not : this will return true on false condition and false on true condition. JavaScript Type operators We can also find the type of data we used in programming By using typeof( ) function.

No comments:

By laptop