JavaScript DataTypes For Beginners
2 min readNov 2, 2020
JavaScript is a high-level, interpreted, non-blocking programming language. it is well-known as a scripting language. Here I’m discussing the Data Type of JavaScript for beginners in a simple way.
- Number: Number is a numeric data type. there are floating-point numbers and integer numbers.
Examples:
a = 1.4
b = 2.2
total = a + b = 3.6 // is floating-point numbersa = 3
b = 4
total = a + b = 7 // is integer numbers.
- String: String represents textual data. you should wrap string by single quote or double quote such as ` ‘Munna’ “Munna” ‘123’ “123” // also a number can be a string when it's warped by quote.
Examples:
var name = "Md riduanul haque"
var name = 'Md riduanul haque'remember!!!var a = '1'
var b = '2'
total = a + b = 12 // it;s string. (if its number then ans will be 3)var firtsName = "Md Riduanul";
var secondName = "Haque"
var fullName = firstName + secondName = "Md Riduanul Haque
- Boolean: Boolean data type is one of two possible values true or false.
Examples
the values of variable yes or no is called true or false. such asvar haveToDrinkCoffee = true;
var haveToDrinkTea = false;when a answer of a question is yes or no then use the boolean type. true and false.
- Null: which has a value that indicates a non-value.
Example
var name = 'munna'if (name == null){
return 0;
}
- Undefined: a value has not been assigned yet.
Example
function name(y) {
if (y === undefined) {
return 'Undefined value!';
}
return y;
}let y;console.log(name(x));
// expected output: "Undefined value!"
- Object: An object is a collection of properties. property has a name and a value.
Example
var Student{
name = 'munna',
age = '30',
phone= 01778899000,
address = 'rangamati'}
- Array: where can store multiple values in a single variable. a collection of the same elements.
Example
var myFriends = ['jony', 'rony', 'giny', 'honey']; // an array
var friendsAge = [23,,33,32,26]; // an array
- Function: A function is a block of code that performs a specific task. suppose you need an additional function to add two numbers. then you can write a function for it.
Example
function sum(a,b){ total = a + b;
return total;
}var add = sum(12, 12);
console.log(add);ans: 24;