Hi, everyone. I decided to start writing about my knowledge in JS to help those who are beginners in dev community.
I hope this article would be helpful to you :)
First of all... What is a variable?
A Variable is a container which stores values.
This value can be changed when we use the word 'let' to declare a variable.
We have the option to declare a variable using the word 'const', too, but this value will not be changing, so be careful.
In Javascript, we have 7 types of data:
let name = 'Debs'; // String (a sequence of text)
let age = 24; // Number
let isGraduated = true; // Boolean (this is a true or false value)
let team; // Undefined (there's no value defined)
let food = null; // Null (represents the intentional absence of any object value)
let symbol = Symbol(); // Symbol
let newObject = {}; // Object
These are primitive data, it means that it is not mutable (except for the objects).
If you are not sure about the type of the variable you are working with, there is a way to discover it by using the command 'typeof' inside the console.log
Example:
let name = 'Debs';
console.log(typeof name); // returns string
Top comments (1)
You missed
bigint
.JS has 7 primitive data types:
string
,number
,boolean
,null
,undefined
,symbol
andbigint
. Everything else is anobject
(which isn't a primitive).Sometimes though, depending on how you define a value - the result of
typeof
may surprise you:Also, be careful how you use the word 'changing' when talking about
const
- it is better to say aconst
cannot be redefined. You are perfectly free to change the properties of anobject
declared as a constant: