Intro to JavaScript


Get Started

  • Types

  • Type Coercion

  • Operators

  • Conditional Statements

  • Loops

  • Functions

  • Objects

  • Arrays

Types

Data types tell the type of data and are necessary to know for operations on variables.

Javascript has 8 datatypes

  1. String

  2. Number

  3. Bigint

  4. Boolean

  5. Undefined

  6. Null

  7. Symbol

  8. Object

    1. Object

    2. Array

    3. Date

Type Coercion

Type Coercion refers to the automatic or implicit conversion of values from one data type to another. This includes conversion from Number to String, String to Number, Boolean to Number, etc., when different types of operators are applied to the values.

Operators

  • Arithmetic Operators

    • Addition +

    • Subtraction -

    • Multiplication *

    • Division /

    • Exponentiation **

    • Modulus %

    • Increment ++

    • Decrement --

  • Assignment Operators

    • \=

    • +=

    • -=

    • *=

    • /=

    • %=

    • **=

  • Comparison Operators

    • \==

    • \===

    • !=

    • !==

    • >

    • <

    • <=

    • <=

    • ?

  • Logical Operators

    • &&

    • ||

    • !

  • Bitwise Operators

    • &

    • |

    • ~

    • ^

    • <<

    • >>

    • >>>

  • Type Operators

    • typeof

    • instanceof

Conditional Statements

If else-if else

if (condition1) {
  //  block of code to be executed if condition1 is true
} else if (condition2) {
  //  block of code to be executed if the condition1 is false and condition2 is true
} else {
  //  block of code to be executed if the condition1 is false and condition2 is false
}

Switch

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}

Loops

JavaScript supports different kinds of loops:

  • for - loops through a block of code a number of times

  • for/in - loops through the properties of an object

  • for/of - loops through the values of an iterable object

  • while - loops through a block of code while a specified condition is true

  • do/while - also loops through a block of code while a specified condition is true

Function

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

function name(parameter1, parameter2, parameter3) {
  // code to be executed
}

Object

Javascript objects are containers for named values called properties.

const person = {
  firstName: "John",
  lastName: "Doe",
  age: 50,
  eyeColor: "blue"
};

Arrays

Arrays are variables that can hold more than one value.

const names=["Amit", "Dinesh", "Suresh"];

Scope and Closure

  • Scope

  • Function Expression and declaration

  • Closure

Scope

  • Block Scope

  • Function Scope

  • Global Scope

Function Expression and declaration

The function keyword can be used to define a function inside an expression.

// Function Expression
const getRectArea = function(width, height) {
  return width * height;
};

// Function Declaration
function calcRectArea(width, height) {
  return width * height;
}

Closure

A closure is a function having access to the parent scope, even after the parent function has closed.

const increment= (function (){
    let x = 0;
    return function(){
        x=x+1;
        return x;
    }
})();

increment();
increment();
increment();

Object, Prototypes & Classes

  • Objects in depth

  • Prototypes and prototype chain

  • Classes


Asynchronous JavaScript

  • Higher Order Functions

  • Promise

  • Async/Await