Course Content
Learn HTML, CSS, and JavaScript from Scratch
About Lesson

JavaScript Data Types

This javascript introductory course, as well as everything else you do in programming, focuses on data storage and manipulation. This data is always accompanied by a type, which tells the computer how to handle the data that it is given. The kind of data is automatically detected when Javascript is executed.

What precisely do I mean when I say this? Consider the following example.

For your information, console.log() prints any data supplied between the parenthesis to the console. Take a look at the code below.

let player1 = 10; 
let player2 = 40; 

console.log(player1 + player2);

Think for a moment: what do you aim for this code to accomplish?

Javascript looks at the defined variables and determines that they are both integers. Javascript then realizes it must output the sum of the two numbers to the console.

The output for the code below will be 50. as in 10+40

Let’s look at another example

Our computer cannot safely solve this without data types:

let x = 25 + "Ronaldo";

Does it even make any sense to add Ronaldo to 25? Will it produce an error, or will it produce a result? JavaScript will treat the example above as:

let x = "25" + "Ronaldo";

When a number and a string are combined, JavaScript treats the number as a string.

We’ll learn how to store and handle the Number data type in the coming lessons.

0% Complete