Variable in JavaScript

Syntax of declaring the variable:

There are two ways of declaring the variable:

  • Declaring and defining the variable at the same time
  • Only declaring and defining in another line
var num1=10;
var strnum1='10';
//declaring
var num1;


//defining
num1=10;
//error
num1=10;


//declaring
var num1;

There are three types of keywords by which we can declare the variable:

  • var
  • let
  • const
//declaring
var num1;
console.log(num1)//undefined

//defining
num1=10;
//let keyword
let num1=9;
//declaring
const num1=12;

note:-

To overcome from the demerit of the JS. Microsoft created on more language which is TypeScript. It is type safe language which runs on the top of the Javascript.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vishal Pathak

Vishal Pathak

72 Followers

love ❤ coding, solving some industry problems technologies: JavaScript, C#, Angular, PLSQL, Docker Want to learn: Python, Go language, AI, ML and Cloud