Introduction

JavaScript is a lightweight, cross-platform, and interpreted compiled programming language with first-class functions.

While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.js.

Key features of JavaScript include:

Variables

You use variables as symbolic names for values in your application. The names of variables, called identifiers, conform to certain rules.

You can declare a variable in three ways:

Data Types

The latest ECMAScript standard defines eight data types, including seven Primitive types and Objects.

Primitives include Boolean, Null, Undefined, Number, BigInt, String, and Symbol.

Example of string declaration:

                const greeting = "Hello World";
            

Functions

Functions are one of the fundamental building blocks in JavaScript. A function is a JavaScript procedure-a set of statements that performs a task.

To declare a function, use the function keyword followed by a name:

function square(number) { 
    return number * number; 
}

            

Control Flow

JavaScript supports a compact set of statements, specifically control flow statements, that you can use to incorporate interactivity.

Use the if statement to execute a statement if a logical condition is true:

if (condition) { 
    statement_1; 
} else { 
    statement_2; 
}