JavaScript Data Types and Type Conversion
JavaScript Data Types and Type Conversion
• const
• var
• let
• Data types
• Primitive data type
• Non primitive data type
• Data types conversion
• Implicit type conversion
• Explicit type conversion
const keyword in JavaScript
Const keyword
It is used to declare and initialize constant
We cannot assign a value to constant again
const x = 4.3
x = 2.3; // It will give an error
x = x + 13; // This will also give an error
function Test() {
let y = 12;
document.write(y); //give 12
}
Test();
document.write(y); // give error of not defined
JavaScript Data Types
JavaScript Data Types
• Primitive data type
The data types which is not a object having no methods are the primitive data type like Number, String, Boolean etc.
• Non-primitive data type
According to requirement, developer create object which have specific properties as well as methods, that have a data
type of non primitive data type. And we also say that it is the reference data type. As Object, Array, RegExp etc
Primitive and non Primitive
JavaScript primitive data types
String It show the sequence of characters enclose in the single or double quotes e.g. “jafricode"
Number It show numeric values e.g. 10, 21, 1.3, -34 etc
Boolean it show possible two value either false or true
Undefined it show the undefined value (variable without value)
Null nothing or not value (instance of an object)
Explicit type casting: Developer convert one type to another when require using function
Implicit type casting in JavaScript
Convert Data type to another data type
Case1:
Case3:
• Numbers to Strings->String()
• Booleans to Numbers->Number()
• Numbers to Booleans->Booleans()