Data types are a particular type of data item that determines what operations can be applied to them. Once a variable is assigned a data type it can be used for computations in the program.
There are 2 kinds of data types, each of which are further divided into sub-types.
Primitive data types: Data types which are pre-defined and supported by the programming language.
Non-primitive data types: Data types which are created by the user and not pre-defined by the language itself.
Number type stands for both integers and floating points. Many mathematical operations are carried out using these numbers.
let n = 123; n=n+10; //mathematical operation on integer (ADDITION) console.log("Your integer number is : " + n) n = 12.345; n=n * 10; //mathematical operation on integer (MULTIPLICATION) console.log("Your float number is : " + n)
let str = "Hello"; let str2 = 'Single quotes are ok too'; let phrase = str + " " + str2; //concatenation of strings console.log(phrase);
Boolean type only has 2 types of return values,
false. This type is usually used to check if something is correct or incorrect.
let isGreater = 4 > 1; if (isGreater=true) console.log("Yes 4 is greater than 1"); else console,log("No 4 is not greater than 1");
A null value is used to declare a variable as empty, or as a variable with an unknown value.
let age = null; //since we do not know what the age is.. console.log("age is " + age);
An undefined value is very similar to null value as it also makes a type of its own. The meaning of undefined is “value is not assigned”.
let age = undefined; //since we do not know what the age is.. console.log("age is " + age);
The definition of objects is created by the user for a defined purpose. The properties of an object define its characteristics. Object properties can be accessed with a simple dot-notation:
var Car = new Object(); Car.make = 'BMW'; //properties Car.color = 'BLACK'; Car.year = 1999; console.log("My car was created in : " + Car.year);
We use arrays to store data in consecutive memory locations; this helps to access them with ease, and it saves time in searching for the relevant data.
var cars = [" Merc ", " Honda ", " BMW "]; console.log("Our cars are :" + cars); //display an array of cars
View all Courses