Data Type in JavaScript
- Data Types
-
As far as data types are concerned JavaScript provides us 3 basic data types which are chosen based on the value assigned to the variable.
-
These 3 data types are:
-
String
-
Number
- Boolean
String Data Type
-
A String is just a combination of words including nos.
-
Any type of character can be stored in a string.
-
It is enclosed in “ “ or ‘ ‘ .
- Printing Double Quotess
-
To print double quoted string we have 2 ways:
- Number Data Type
- Numbers in JavaScript are just numbers , no integers and no floats , just plain numbers
- Boolean Data Type
-
Booleans can only have two values: true or false.
For Example
var myName=“Nishant”;
OR
var myName=‘Nishant’;
For Example
a. var msg=“ \”Hello\” “;
OR
b. var msg=‘ “Hello” ‘;
For Example
var salary=40000;
var pie=3.14;
var phoneBill=2000;
For Example
var x=true;
var y=false;
Booleans are often used in conditional testing.
-
// declaring one javascript variable
var firstName;
// declaring multiple javascript variables
var firstName, lastName;
// declaring and assigning one javascript variable
var firstName = ‘Nishant’;
// declaring and assigning multiple javascript variables
var firstName = ‘Sachin’, lastName = ‘Gupta’;
Variables Decl Rules
-
Variable names must begin with a letter and can have digits also.
-
Variable names can also begin with $ and _
-
Variable names are case sensitiveDefault value of a variable is “undefined”