01-03 Operators and Expressions
01-03 Operators and Expressions
Operators
o Assignment Operators
o Arithmetical Operators
o Comparison Operators
o Logical Operators
o Bitwise Operators
o String Operators
o Conditional (Ternary) Operator
o Type Operator
o Comma Operator
o Void Operator
o Delete Operator
o Spread and Rest Operator
Expressions.
o Primary Expressions.
o Object and Array Initialisers.
o Function Definition Expressions.
o Property Access Expression.
o Invocation Expression.
4. Logical Operators
Use: These Operators combine multiple conditions.
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
5. Bit-Wise Operators
Use: Bitwise operators are used to preform bit level operations.
Operator Meaning
& AND
| OR
^ XOR
- NOT
<< Left Shift
8. Type Operator
Use: This operator are used to check type of variable or value.
Operator Meaning
typeof Returns the type of variable
instanceof Check if the object is an instance of specific class.
9. Comma Operator
Use: It evaluates multiple expressions and returns the last one.
Primary Expression.
Primary expressions are simple and foundational elements in JavaScript.
They include literal values (numbers, strings, booleans, etc.), reserved keywords (this,
null, etc.), variable references, and grouping with parentheses.
These expressions do not rely on other operators to evaluate and form the basis of more
complex expressions.
In JavaScript, primary expressions are the most basic expressions that are not require
further evaluation or operators.
They are the simplest elements of the language and can directly represent values or
references.
Types of Primary Expressions in JavaScript
Literals: These are fixed values that directly represent a value in the code. Literals are
often used to define primitive data types.
o Number Literal: 42 // A numeric value
o String Literal: "Hello, world!" // A string of text
o Boolean Literal: true // A boolean value, false // Another boolean value
o Null Literal: null // Represents the intentional absence of any object value
o Undefined Literal: undefined // A value that has not been defined yet
o Object Literal: { name: "Alice", age: 25 } // An object with properties
o Array Literal: [1, 2, 3, 4] // An array containing values
Array Initializer.
Array Initializer is shorthand method to create array using literal syntax.
This is most convenient method to define and initialize these data structure without
explicitly call constructors like new Array().
Array initializer allow you to create array by listing the elements within square brackets [ ].
Sometimes it is also called as Array Literals.
We can define elements of array separated by comma.
Syntax:
Subject: Java Script Notes Print Date: [16/Oct/24], Page 13 of 19
Var newArray = [ element1, element2, ………. ]
We can create array with empty slots.
Array can contain other array, which represent multidimensional data.
Example:
Bracket Notation
o Bracket notation allows the use of dynamic property names, variables, or strings
with spaces and special characters.
o Bracket notation is more flexible.
o Syntax: object["property"]
o Example: