Saturday, December 26, 2020

Javascript tutorial part- 2 variable and datatypes.

 



Variable name is name of memory location in which we are going to store data.

Three keywords  are used for declare variable.

1.     Var

2.     Let

3.     Const

Var and let are used for declaring variable i.e that data may vary in the current program and const is the keyword used to declare constants. Constance means once defined we cannot alter its value.

let name=”Muthu karthikeyan”;

let isMarried=true;

let age=46;

name is assigned a string so name is a string.

isMarried is assigned true value which is a Boolean

age is assigned a number datatype. So it is a number data type.

console.log(“name”);

console.log(name)

 

output:

name

Muthu karthikeyan

The data which is within double quotes is printed as itself.

Without quotes is treated as variable and prints its value.

There is an another data type which it called is undefined.

For example.

let  fullName

console.log(fullName);

output:

undefined.

The output is undefined because we still didn’t assign any value to variable name called as fullName.

const a=10;

a=25;

output:

error. 

output is error because we are altering a constant. a is a constant because it declared with keyword const.

-will continue.

S.MUTHU KARTHIKEYAN

91 96293 29142