There are many types of data in JavaScript, but mainly two types of data and they are the Primitive data and Reference data.
There are many things to say about these two types of data, but without confusing you guys, Primitive Data Types are data that are stored directly on the location the variable accesses. This means when you access primitive data you access it by its mains values. Reference data types are stored in a pointer location on the memory.
Examples of Primitive data (6)
I used a few yesterdays but I did not talk about it, but you can get something if you read both tutorials.
- String
- Boolean
- Number
- Null
- Undefined
- Symbols (Introduced in ES6)
Reference Data
- Object Literals
- Arrays
- Functions
- Dates
- Others that can be stored
So, let's talk about the PRIMITIVE DATA TYPES
// String
const name = 'vidder';
console.log(typeof name);
This will log on the console that it is a string.
// Number- if you put quotes around the number it will turn to a string
const score = 48;
console.log(typeof score);
// Booleans are true or false - if you put a quote around Boolean it will turn to a string
const sportMan = true;
console.log(typeof sportMan);
// Null
const ball = null;
console.log(typeof ball);
// You will get Object. This is a kind of little mistake in the JavaScript world. This does not mean Null is an object, it is a primitive type but mistakenly picked as object.
// Undefined
let phone;
console.log(typeof phone);
// Symbol
const sym = Symbol();
console.log(typeof sym);
These are all the Primitive types in JavaScript. I hope you understand them, but you could ask questions on the comment section if you have issues with anyone.
Let's get to REFERENCE TYPES.
All reference types will come back as Object.
// Array
const sports = ['Football', 'Basketball', 'Cricket', 'Rugby'];
console.log(typeof sports);
// Object Literals
const address = {
country: 'USA',
state: 'Las Vegas'
}
console.log(typeof address);
// Date
const today = new Date();
console.log(today);
console.log(typeof today);
// In date aspect, the first log will show the current date and the type will show object.
These are the basics you need to know about Data types in JavaScript. You can pop on comments if you have questions. I will build a simple system tomorrow and I will try to continue a little with this JavaScript progressive tutorial.
Thank you!
I am enjoying your tutorials a lot..egarly waiting for the upcoming system of tomorrow 😍😍
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Another good tutorial. I think I am learning from this. I will also start posting my little coding experience as I am learning.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Good. Which language are you learning?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I am learning html and css first for now but I am still at the basis.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit