Jobs
Blogs
Courses
Mentorship
Partners
For Employers
e2e logo

Web development (Learn basic of javascript)

mac

 JAVASCRIPT

                                                                                                                                                                                                                                                                                                                               


 JS COMMENTS

     *It is most important in java script.

    *It is used to explain the java script code.

 Single line comments

   * Single line comments start with //. 

   *Any text between // and the end of the line will be ignored by JavaScript.

          Example

  Multiple line comments 

    *Multi-line comments start with /* and end with */.

     *Any text between /* and */ will be ignored by JavaScript.

              Example 

             

Variables

     * Variables are containers for storing data   

          Example 

       In this example, x, y, and z, are variables, declared with the let keyword: 

 Operators

 assignment operator 

   *The assignment operator (=) assigns a value to a variable. 

              Example  

   addition operator 

    *The addition operator (+) adds numbers: 

                   Example  

  String operator

     To add

   Logical operator

       &&  AND gate

    || OR gate

      ! NOT gate


 AND gate

*It is the strict gate, It will pass only whether the 2 statement is pass

0  && 0 = 0

0 && 1 = 0

1 && 0 =0

1 && 1 = 1

OR gate

* It will pass whether the 1 statement is pass

0 || 0 = 0

0 || 1 = 1

1 || 0 = 1

1 || 1 = 1  

Examples

         *  In this line we want to see whether the two condition   is right.

         *  First we saw x is greater than 2 and  y is smaller than 5.

         * In this case x is greater than 2 and y is not less than 5, So it is false.

                                                                                                                     

Datatypes

Strings

(let doll = "It's alright";)


Numbers

Let x=2;

  

 Boolean

      Booleans can only have two values: true or false.

 Array

      If you have a list of items , storing the cars in single variables.


         if you want to loop through the cars and find a specific one? And what     

  if you had not 3 cars, but 300?

         The solution is an array!

        An array can hold many values under a single name, and you can  

access the values by referring to an index number.

 Example

 

  Object

     In real life, a car is an object.

        A car has properties like weight and colour, and methods like start and    stop:

        All cars have the same properties, but the property values differ from car to car.

 Functions

       A JavaScript function is a block of code designed to perform a particular task.

A JavaScript function is executed when "something" invokes it (calls it).

Example

 

 If/Else

Conditional statements are used to perform different actions based on different conditions.

Use if to specify a block of code to be executed, if a specified condition is true

Use else to specify a block of code to be executed, if the same condition is false

Use else if to specify a new condition to test, if the first condition is false

Example

                                        

Switch

              

     * The value of the expression is compared with the values of each case.

    * If there is a match, the associated block of code is executed.

    * If there is no match, the default code block is executed.


Example

 

    For loop

loops through a block of code a number of times.

Statement 1: sets a variable before the loop starts (let i = 0).

Statement 2 : defines the condition for the loop to run (i must be less than 5).

Statement 3 : increases a value (i++) each time the code block in the loop has been executed.

 

Example

                              

Map

*We set the value of the key in a map

*We get the value of a key in a map

   Example