Friday, July 5, 2024

JavaScript operators

             

     JavaScript Operators 

  

1] Arithmetic Operators 

2]  Assignment Operators

3] Comparison Operators   

4] String Operators   

5]  Logical Operators

6] Bitwise Operators

7] Ternary Operators


1] Arithmetic Operators JavaScript 

    1] Addition (+)

    2]  Subtraction (-)

    3] Multiplication  (*)

    4] Exponentiation (**)

    5] Division  (/)

    6]  Modulus   (%)

    7]   Increment  (++)

     8]  Decrement (--)

  

         Example :-

  

Operators

 Name

Example

Result

 

      +

 

Addition

 

 6+2

 

8

      

      -

 

Subtraction

 

6 - 2

 

4

 

      *

 

Multiplication

 

6 * 2

 

12

   

     ** 

 

Exponentiation

 

2 **3

 

8

 

      /

 

Division

 

6 / 2

 

3

    

     %

 

Modulus

 

7 % 3

 

1

  

    ++    

 

Increment

 

 6 ++

 

7

 

     _ _

 

 

Decrement

 

6 - -

 

5


2]  Assignment Operators JavaScript

   1]  Assignment (=)

    2]   Addition Assignment (+ = )

    3]  Subtraction Assignment (- =)

    4] Multiplication Assignment (* =)

    5] Division Assignment (/ =)

    6] Remainder Assignment  (% =)


    Example :-

Assignment operators



3] Comparison Operators JavaScript   

    1] Equal  to  (==)

   2]  Equal value and equal type (= = =)

   3] Not equal (! =)

   4] Not equal value or not equal type (! = =)

   5] Greater than ( > )

   6] less than (< )

   7] Greater than or equal to (> = )

   8] less than or equal to (< =)

 Example :-

Comparison Operators

4] String Comparison  

 String  comparison operators use compare two strings to determine

 Relative equality 

   1]  Equality (= =)

   2] Inequality ( ! =)

    3] Greater than ( > )

    4] Greater than or equal to (>= ) 

    5]  Less than (< )

    6] Less than  or equal to ( <= )

   Example :-

String Comparison

5]  Logical Operator JavaScript

  1]  logical and (&&)

  2] logical or ( | | ) 

  3]  logical ( ! )

Logical Operator 

Example :-

Logical Operator


6] Bitwise Operators

1]  AND  ( & )

2] OR ( | )

3] NOT ( ~ )

4] XOR ( ^)

5] left  shift ( << )

6] right shift ( >>)

Bitwise Operators

Example :-

Bitwise Operators Example :


7] Ternary Operators

 1] condition 

 2] expression_if_true

  3] expression_if_false 


Syntax  :=

  condition  ? expression_if_true : expression_if_false

Example :-


let age =18;
let message;
if(age>=18){
    message="you can vote Yes";
}
else{
    message="you can't vote No ";
}
 console.log(message);

Output :- 




Related Post :-

javascript variable with example

What is data type in JavaScript

Introduction to JavaScript



Wednesday, July 3, 2024

Javascript variable with example


 

what is a variable  JavaScript

 1] JavaScript variables are containers for storing information.

2]   JavaScript store data value.

JavaScript Variable 

1] var    

2] let

3] const


1] var   

   1]  JavaScript variables must identified with unique names.

  2]  Unique names call identifier.

 3]  identifier descriptive name is the (total volume,  age, sum).

 4]   Creating a variable  in JavaScript is declaring the variable.

Example :-


JavaScript Code :


    var a= 10;
    var b=20;
    var c= a+b;
    document.write(c);

Output :

variable javascript

2] let :-

 1] let statement separate the variables by comma.

2]  let can not be redeclared.
 

Example :-

JavaScript Code :


{
    let value = 50;

document.write("Inside the function
value = " + value);  
}
document.write("<br> Outside the function value = " + value);  

Output

let variable javascript


3] const :-

  1] JavaScript  const is keyword use declare a variable .
  2]  const variable cannot be reassigned a new value.
  3]  const keyword declare a variable do not change the value.
  4] const variable creates only reference value.

Example :-

JavaScript Code :

const x = 90;  
     document.write("const variable value x = " + x);  

OutPut :-


Related Post :-

What is data type in javascript



what is data type in javascript

 

JavaScript console.log()


What is the console.log() Method

1] console.log() is a built-in function.

2] console.log() is allows to output Message .

3]  And value to the console.

4] console.log() use for debugging & understanding  code.

5] log() method writes a message to the console.

6] log() method useful to testing purposes.

7] console.log() method  is javaScript logs message or data to console.

8] console.log()  debugging by displaying object properties, program flow or variable value .

9] console.log() method supported all browsers. 

Example :- chrome, internet explore,  Edge , Firefox , Safari, Opera, ext.


Console.log(); 

    Syntax 

         console.log(" ");

 

Example :-

 JavaScript code -


console.log
(" Welcome learn programming language to
link-https://webdesigningtheory.blogspot.com/");

Output :-

console.log() example with output
         

             Data Type  :-  

1] String  data type 


   Example :-

 JavaScript code -


let str =
"Welcome to learn programming language
link-https://webdesigningtheory.blogspot.com/";
console.log(str);


Output :-
string data type javascript

2] number  data type 


   Example :-

 JavaScript code -


let A =7;
console.log( A);

Output :-
number  data type  javascript


  3] Boolean  data type 

             1]  Boolean datatype returns either two value - true or false .
             2]   boolean  used  object, condition, variable, expressions etc. 
             3]   boolean terms of True or False value.
   
 Example :-

  JavaScript code -


function one(){
    console.log(Boolean(20));
}
one();

Output

boolean  value true

 Example :-

  JavaScript code -


function one(){
    console.log(Boolean(""));
}
one();


Output :-

javascript datatype boolean outpue false


4] undefined  data type 

     1] undefined value  is global read only variable .
      2] undefined is type of primitive type.
   Example :-

 JavaScript code -


let myvalue;
if (typeof myvalue==="undefined"){
    console.log("myvalue is undefined");
}
else {
    console.log("myvalue is defined");
 
}


Output 

javascript  undefined  data type

5] null  data type 

          
   Example :-

 JavaScript code -


const value =null;
if(value)
    {
    console.log("value is  not null");
}
else {
    console.log("value is  null ");
}


Output:-