Science Knowings: JavaScript Course For Social Media

Variables and Data Types

Variables and Data Types

Welcome back! In this session, we'll dive into variables and data types, the fundamental building blocks of JavaScript programs.

What are Variables?

Variables are named containers that store data in your program. They allow you to reference and manipulate data throughout your code.

Declaring Variables

You declare variables using keywords like var, let, and const followed by the variable name and an optional assignment value (var name = "John").

Variable Naming Conventions

Use meaningful and descriptive names for your variables (e.g., firstName, productPrice). Avoid using reserved keywords (if, for) and start with letters or underscores (_).

Data Types in JavaScript

Data types define the type of information a variable can hold. JavaScript has various data types like numbers, strings, booleans, arrays, and objects.


Numbers represent numeric values. You can perform arithmetic operations like addition, subtraction, multiplication, and division on numbers.


Strings represent textual data enclosed in quotes (single or double). You can use string concatenation (+) to join multiple strings ("Hello" + " World!").


Booleans represent logical values: true or false. They are used in conditional statements to control program flow.


Arrays are ordered collections of items that can hold various data types. You can access and modify elements using their index within square brackets ([]). (var colors = ['red', 'green', 'blue'])


Objects are unordered collections of key-value pairs. Keys are like property names, and values can be any data type. Objects allow you to store and organize data in a structured way (var person = { name: 'Alice', age: 30 }).

Next Up: Working with Strings

In the next session, we'll explore how to work with strings in JavaScript, including string manipulation techniques. Follow us to learn more!