Main Menu

Pages

JavaScript Tutorial #2: Variables and Data Types - Spider Cyber Team


JavaScript Tutorial #2: Variables and Data Types

In our previous lesson, we introduced JavaScript. Today, we will learn how to store data using Variables and understand the different Data Types available in JS.


1. What is a Variable?

Think of a variable as a labeled container or a box where you can store information. In modern JavaScript, we have three ways to declare a variable:

  • let: Used for variables that can change later.
  • const: Used for constants (values that stay the same).
  • var: The old way (not recommended for modern projects).

2. How to Declare Variables

Here is how you can write them in your code:


let age = 25;        // The value can be changed
const name = "Spider"; // The value is constant
age = 26;            // This is allowed
// name = "Cyber";   // This would cause an error!

3. Data Types in JavaScript

JavaScript variables can hold different types of data:

  • String: Text wrapped in quotes (e.g., "Hello World").
  • Number: Integers or decimals (e.g., 10, 3.14).
  • Boolean: Logical values, either true or false.
  • Array: A list of values (e.g., ["Python", "JS", "PHP"]).
  • Object: Complex data structures (e.g., {name: "Spider", age: 5}).
  • Null & Undefined: Representing empty or unassigned values.

4. Practical Example

Try running this code in your browser console:


let teamName = "Spider Cyber Team";
let membersCount = 1000;
let isActive = true;

console.log("Team: " + teamName);
console.log("Members: " + membersCount);
console.log("Is the team active? " + isActive);


Conclusion

Understanding variables and data types is the foundation of any programming language. Practice creating your own variables and see how they work!

Stay Updated!

Join our Telegram channel for the latest JS scripts and tech tutorials:

Join Spider Cyber Team on Telegram

Comments