Javascript

Javascript is a versatile programming language used for creating dynamic and interactive web content.

Basic Concepts

Variables and Data Types

Storing Information with Variables

In JavaScript, variables are like boxes where you can store information. You can name a box, put something inside, and use it later.

let name = "Alex";
let age = 14;
let isStudent = true;
  • let is a keyword to declare a variable.
  • The = sign assigns a value.
  • You can store text, numbers, or true/false values.

Different Data Types

  • String: Text inside quotes, like "Hello".
  • Number: Any number, like 42 or 3.14.
  • Boolean: true or false.

Why Use Variables?

Variables allow you to write flexible and reusable code. For example, you can ask a user's name and greet them with it.

let userName = prompt("What's your name?");
alert("Welcome, " + userName + "!");

Changing Variable Values

You can change what's inside a variable any time.

let score = 0;
score = score + 10;

Now, score is 10!

Examples

  • Saving a user's high score in a game

  • Checking if someone is logged in or not

In a Nutshell

Variables store information, and data types tell us what kind of information it is.