JavaScript Beginner Day 2: Variables & Data Types

Goal of this Day

Today you will learn:

By the end, you will be able to store and use data in JavaScript.

Step 1: Variables

Variables are used to store data.


let name = "John";
let age = 25;

let, const, var


let city = "Berlin";
city = "Hamburg"; // allowed

const country = "Germany";
// country = "France"; // error

Step 2: Data Types

String


let name = "Alice";

Number


let age = 25;

Boolean


let isStudent = true;

Step 3: Using Variables

You can combine variables in output:


let name = "John";
let age = 25;

console.log(name + " is " + age + " years old");

Practice


let name = "John";
let age = 25;
let isStudent = true;

console.log(name + " is " + age + " years old.");

Task

Create 3 variables about yourself and print them in one sentence.

Example:


let name = "Alex";
let age = 18;
let hobby = "gaming";

console.log("My name is " + name + ", I am " + age + " years old and I like " + hobby + ".");