JavaScript Data Types
Variables are named containers that can store data and Type is a classification identifying one of various types of data. Data can come in many different types
Strongly Typed
Normally most of the programming languages feature strongly typed variables. When programming with these languages, we should explicitly state what sort of data we are dealing with, and use of those data should follow strict rules applicable to its datatype. For example, we can't add a numeric and a string together in Strongly Typed languages.
Weakly Typed
On the other hand, Javascript variables are loosely typed, meaning that a variable can hold any type of data. When we deal with data in Javascript, we often don't need to specify type of data, instead Javascript will work that out for itself. Moreover, when you are using different types of data at the same time, JavaScript will work out behind the scenes what you're trying to do
Javascript Data structures
Even though Javascript is loosely typed language, it actually does have data types (also called primitive types). Normally there are three Primary data types and two Composite data types and Two special Data Types in Javascript
Primary Data Types (Primitive)
- String
- Number
- Boolean
Data Type | Description |
String | represents sequence of characters e.g. "hello" |
Number | represents numeric values e.g. 100 |
Boolean | represents boolean value either false or true |
Composite Data Types (reference)
- Object
- Array
Special Data Types
- Null
- Undefined
- String : A strings of any characters enclosed in quotes is a string primitive.
- Number : A number by itself is a number primitive, all numbers in JavaScript are 64-bit floating-point numbers.
- Boolean : It will store Variables or expressions which are either true or false.
- Object: A collections of properties and methods. In Javascript, anything that is not a primitive is an Object.
- Arrays : Arrays are regular objects, both objects and arrays can have properties and methods.
- Null : It has only one value in JavaScript: null.
- Undefined : It treated as a variable that has been declared, but has never had a value assigned to it.
« Previous Next »