1.2
The 7 primitive data types
Examples with a Run button are editable. Underlined terms open a short definition.
The 7 Primitive Data types
- To check the Data type of any Varible / Value
console.log(typeof 'ChandraPrakash');
- Way of Declaring Variables
var a; // variable
var a = 1,
b = 2,
c = a + b; // one line
const PI = 3.14; // constant
let z = 'zzz'; // block scope local variable
('use strict'); // Use strict mode to write secure code
x = 1; // Throws an error because variable is not declared
// Creates property on global scope. [Not reccomend to wright Variable without Declaring]
- Number: Floating point numbers -> Used for decimal and integers.
let age = 23;
console.log(typeof age);
- String: Sequence of characters -> Used for text.
let firstName = 'ChandraPrakash';
console.log(typeof firstname);
- Boolean: Logical type that can only be true or false -> Used for taking decisiions.
let fullAge = true;
console.log(typeof fullAge);
- Undefined Value by a variables is not yet defind(“empty value”).
let children;
console.log(typeof children);
- Null: Also means ‘empty value’.
let myNull = null;
console.log(typeof myNull);
-
Symbol (ES2015): Value that is unquie and cannot be changed [Not useful for now].
-
Biglnt (ES2020): Larger integers than the Number type can hold.
Your last opened chapter is saved in this browser when local storage is available.
Discuss this section
Questions, corrections or a better example? Comments use GitHub Discussions.