In this module, we will explore the fundamental building blocks of JavaScript: variables, data types, and operators.

Variables:

- Variables are containers that store values.
- In JavaScript, variables are declared using the let, const, or var keywords.
- let and const are block-scoped, while var is function-scoped.

Data Types:

- JavaScript has several data types, including:
    - Numbers (integers and floating-point numbers)
    - Strings (text and character sequences)
    - Booleans (true and false values)
    - Null (the absence of value)
    - Undefined (an uninitialized variable)
    - Objects (collections of key-value pairs)
    - Arrays (collections of values)

Operators:

- Operators are symbols used to perform operations on values.
- Arithmetic operators: +, -, *, /, %
- Comparison operators: ===, !==, >, <, >= , <=
- Logical operators: &&, ||, !
- Assignment operators: =, +=, -=, *=, /=, %=

Examples:

- Variable declaration:


let name = 'John';
const age = 30;
var occupation = 'Developer';


- Data type examples:


let num = 42; // Number
let str = 'hello'; // String
let isAdult = true; // Boolean
let nullValue = null; // Null
let undefinedValue; // Undefined
let person = { name: 'John', age: 30 }; // Object
let colors = ['red', 'green', 'blue']; // Array


- Operator examples:


let sum = 2 + 2; // Arithmetic operator
let isEqual = 2 === 2; // Comparison operator
let isTrue = true && false; // Logical operator
let assignedValue = 5; // Assignment operator


Syntax:

- Variable declaration:


let/const/var variableName = value;


- Data type syntax:


let variableName = value; // Number, String, Boolean, Null, Undefined
let object = { key: value }; // Object
let array = [value1, value2, value3]; // Array


- Operator syntax:


let result = operand1 operator operand2; // Arithmetic, Comparison, Logical operators
let variableName operator= value; // Assignment operators


By mastering variables, data types, and operators, you will be able to write effective and efficient JavaScript code. Remember to practice and experiment with different examples to solidify your understanding.

Leave a Reply

Shopping cart0
There are no products in the cart!
Continue shopping
0