var x = “Hello”; // Assigning a string

var y = 12; // Assigning a number

Data types play a very important part in programming and understanding them is a fundamental part of your learning of JavaScript and its concepts. JavaScript handles the assigning of data types for you when you declare your variables. It will detect the data type you have assigned, based on your syntax. You do not have to specifically state which type of data your variable holds, like you might do in a different programming language.

It’s important to understand both the benefits and limitations of each data type, to help you to understand what you can do with each. So let’s first understand just why data types are so important.

Consider the following snippet of code: