🔢 Variables and Data Types

Lesson

🔢 Variables and Data Types

What is a Data Type?

Data type basically means what kind of data do you want to store in your program, there are 5 different data types in JavaScript that we can use, let’s have a look at what they are!

 

 

Data Types in JavaScript

In JavaScript, there are 5 different data types:

  1. String
  2. Number
  3. Boolean
  4. Undefined
  5. Null

String

Strings are variables which hold a bit of text. This is what we’ve been doing so far.

let name = "Amy";
alert(name);

Number

We can also make variables with numbers in them. In JavaScript this can be any kind of number, regardless of whether it has decimal points or not.

let age = 18;
alert(age);

Try It Out

https://repl.it/@LilyChenjh/Data-Type

Boolean

You know how computers use ones and zeroes? Booleans are just exactly that, “true” or “false”, 1 or 0?

In JavaScript and most text coding languages, true means 1 and false means 0.

let isStudent = true;
alert(isStudent);

Undefined

As mentioned in the first Variables lesson, variables are undefined until we tell them what to contain.

let job;
alert(job);   // it's undefined

job = "teacher";    // put something in job
alert(job);

Null

Null is an interesting one. Later on, you’d need to tell JavaScript that there is no data to use. For this we’d use null.

let school = null;   // homeschooling
alert(school);

Try It Out

 

Fun game for today will be letting the program know what school you from and what grade you are! See if you can get the result similar to the one at the bottom, feel free to change sentences!

https://repl.it/@LilyChenjh/null

@

Not recently active