Data Structures in JavaScript
Data structures can be presumed as a paradigm to save or represent data in a computer so that it will be able to be used efficiently. We will be discussing data type in JavaScript. JavaScript is a programing language whose data model is “loosely typed” which means the determination of its data type is dynamic.
What does it mean to be dynamic? data type in JavaScript can be changed, it is known as “dynamic typing”. It’s distinct if we conduct comparing with Java that applies “static typing”. Here is an instance that you can distinguish between JavaScript and Java:
Data types that are primitive
These data type represent a value directly.
- String
The type stores character as its value (letter, number, and symbol) and the value will be into double quotation mark (“ “) or single quotation mark (‘ ‘). Below is the example:
const string = “hello world”;
2. Number
The number represents integer and floating number (decimal). There are many operations for this type some of them are time (*), summation (+), subtraction (-), and divide (/). As you can see below for an example.
const number = 10;
3. Boolean
This type has two values only. It is “true” or “false”. Boolean will be used often to check data. Simply, boolean could be analogized as a switch that has two conditions, on or off.
let isLightOn = true;
let isLightOn = false;
4. Null
Null represents emptiness only or we could say no data.
Example: let data = null;
5. Undefined
A data type that is undefined. It means there is no value in that data. This value usually appears when we want to define a variable but do not input any value in it.
example: let undefined;
//output: undefined