DEV Community

VIDHYA VARSHINI
VIDHYA VARSHINI

Posted on

Getting Started with JavaScript

JavaScript is a programming language used to make the web pages interactive. It can update and change both HTML and CSS.
Data Handling: In JavaScript, it refers to collect,store, process and manipulate data.

JS Data types:
• String
• Number
• Boolean
• Symbol
• Undefined
• Null

Big int: It is used for storing big integer values in javascript [Ex:123456789012345678901234567890]

In Java,data types can be divided into two groups: primitive and non-primitive.
Primitive data types:
• byte - 1 byte = 8 bits
• short - 2 bytes [16 bits]
• int - 4 bytes [32 bits]
• long - 8 bytes
• float - 4 bytes
• double - 8 bytes
The numbers can be stored from [-128 to +127] for the case of 1 byte.
The number can be stored from [-32,768 to 32,767] for the case of 1 short.

Identifiers: It is the name which is given to the variables,function,arrays etc.
Ex: maths = 70; // "maths" is the identifier.

How to declare variable in JavaScript:
• var
• let
• const
Ex: let name="Vidya";
let age=24;

In Java, the variable can be declared as:
string name="Vidya";
int age=24;

Statically typed programming language: If a variable has to be declared, data type must be declared before defining the variables.
Java is a statically typed programming language.
Dynamically typed programming language: In this, no need of mentioning the type of variable when declaring it.The type is automatically decided at runtime, based on the value assigned.
JavaScript is a dynamically typed programming language.

var: It is a keyword used to declare a variable in JS. There are two types of scopes : local scope and global scope.

Local scope: In this, a variable can be accessed only inside a specific part of a code like a function.
Global Scope: If a variable is declared outside any function using var, it becomes globally scoped i.e, it can be accessed from anywhere in the code.

In Java, redeclaration cannot be done, but reinitialization can be done.
In JavaScript, only var allows redeclaration,let and const do not.

let: It offers block scope, which means the variable exists only within the {}.
Ex: let name=John;
let i=15;

const: It is used to declare a variable whose value cannot be changed once the value is set.
Ex: const i = 10;
i = 15;
// Error
Here, error will occur because a variable declared with const cannot be changed after its initial value is set.

Top comments (0)