DEV Community

Cover image for Data types in JS
Manu Martinez
Manu Martinez

Posted on

Data types in JS

Pay attention ▲, this post will teach you whatever you need to understand what are data types and how can you select the type you need to accomplish your target 🥳.

First of all you need to understand that JS is dynamic typed, if you read our all post you have already known what does it mean 😋.

Dinamic typed ❤️

OMG!!, It sounds really crazy, it sound really difficult but no, if you think in the sense of dynamic you will understand that typed are assign in *execution time *, it means that when you are writing your code you won't need to indicate what are exactly the types 😏. It's one of the most clearly advantage if you are learning JS as a first programming language.

Then 😇, Why must I know what are data types if JS makes implicit assignations?

You really need to know what types of data do you have available, because you can prepare your code to work with those. Let's going to start with the simple data 😏

  • String -> It means literally chars chain, for example word is a string because it's text. This data type is composed by quotes, doesn't care, double, simple, accent whatever, the main important think is put the text inside the quotes.
console.log("My first string")
Enter fullscreen mode Exit fullscreen mode
  • Number -> Like his name said, it's a number, a pointing number, a real number, whatever that means exactly a Real Number.
let myAge = 15
Enter fullscreen mode Exit fullscreen mode
  • Boolean -> It means true or false, easy isn't it 🤓?, it only indicates a state, it's one of the most important data type, since, you will need to control the execution steps thankfully to Boolean values.
let truth = true
let ohh = false
Enter fullscreen mode Exit fullscreen mode
  • Null -> It can be really confuse, it means that you have created a value that will be change soon and first you assign to null. One of the most important uses is to indicate when a function get an error, normally you will return null when there was a failure in the execution time.
let myNull = null
myNull = "Hola"
console.log(myNull)
Enter fullscreen mode Exit fullscreen mode
  • Undefined -> It appears when you declare a var and you don't assign any value. It usually appears when you try to get a value from any var/let/const which has never been defined. It's usually identified such a developer error.
let a;
console.log(a) // it prints undefined
Enter fullscreen mode Exit fullscreen mode

I know, 😊 there are more data types, means more complex data types, but the basic data types are all of above. Really, it's so important to understand what are exactly each one, you need to know what are the difference 😉 and how to use it.

In the following post we will deep into more detail about complex data types, understanding what does it mean. For now, I strongly recommend you to study and research more about data types, you can write down your own personal notes and use it for remembering all data types 😤.

Top comments (0)