Data Types
JavaScript has several built-in data types, which are used to represent different kinds of values.
Undefined: It means that a variable has been declared but doesn't have a value yet.
Null: It represents the intentional absence of any value.
Boolean: It has only two values, either "true" or "false". It's used for making decisions.
Number: It represents any numeric value, like whole numbers or decimals.
String: It represents a sequence of characters, like words or sentences. It is enclosed in quotes.
Symbol: It's a unique and immutable value often used as a special identifier.
Object: It's a collection of properties and methods, like a container that holds related information. Array: It's a list of values stored in a specific order.
Function: It's a reusable block of code that performs a specific task.
Remember, these are the basic data types, and JavaScript allows you to use them in combination or transform them as needed.
Operators
JavaScript provides a variety of operators that allow you to perform operations on values and variables.
Operators allow you to perform various computations, comparisons, and logical operations to manipulate and work with values in your JavaScript code.
Here are some of the most commonly used operators in JavaScript:
Arithmetic Operators: Used for mathematical calculations.
Addition: +
Subtraction: -
Multiplication: *
Division: /
Remainder (Modulus): %
Exponentiation: **
Assignment Operators: Used to assign values to variables.
Assignment: =
Addition assignment: +=
Subtraction assignment: -=
Multiplication assignment: *=
Division assignment: /=
Remainder assignment: %=
Comparison Operators: Used to compare values and return a boolean result.
Equal to: ==
Not equal to: !=
Strict equal to: ===
Strict not equal to: !==
Greater than: >
Less than: <
Greater than or equal to: >=
Less than or equal to: <=
Logical Operators: Used to combine or negate logical expressions.
Logical AND: &&
Logical OR: ||
Logical NOT: !
Increment/Decrement Operators: Used to increase or decrease the value of a variable.
Increment: ++
Decrement: --
String Operators: Used for string concatenation.
Concatenation: +
Ternary Operator: A shorthand way to write conditional statements.
Ternary operator: condition ? expression1 : expression2
Typeof Operator: Used to determine the type of a value.
Typeof operator: typeof
Member Access Operators: Used to access properties or methods of objects.
Dot notation: object.property
Bracket notation: object['property']
These are a few examples of the operators available in JavaScript:
Example 1:
let a = 5;
let b = 3;
let c = 8;
let result = (a + b) * c - (a % b);
console.log(result);
Example 2:
let age = 20;
let isAdult = age >= 18 ? "Adult" : "Minor";
console.log(isAdult);
Output: "Adult"
Comments
Post a Comment