0% found this document useful (0 votes)
11 views19 pages

01-03 Operators and Expressions

Uploaded by

tejasbadgujar238
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views19 pages

01-03 Operators and Expressions

Uploaded by

tejasbadgujar238
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Basics Of JavaScript Programming

 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.

OPERATORS AND EXPRESSIONS.


1. Assignment Operators
Use: Assignment Operator is used to assign a value to the variable.
Operator Meaning
= Equal To (Basic Assignment)
+= Plus Equal To (Addition Assignment)
-= Minus Equal To (Subtraction Assignment)
/= Divide Equal To (Division Assignment)
*= Multiply Equal To (Multiplication Assignment)
%= Modulus Equal To (Modulus Assignment)
**= Exponentiation Assignment

Subject: Java Script Notes Print Date: [16/Oct/24], Page 1 of 19


2. Arithmetical Operators
Use: Arithmetical Operator are used to performing basic arithmetical operations.
Operator Meaning
+ Addition
- Subtraction
/ Division
* Multiplication
% Modulus
++ Increment
-- Decrement
** Exponentiation
3. Comparison Operators
Use: Comparison Operators are used to compare the values.
Operator Meaning
== Equal To
=== Strict Equal To (Checks value and type)
!= Not Equal To
!== Strict Not Equal (Checks value and type)
> Greater than

Subject: Java Script Notes Print Date: [16/Oct/24], Page 2 of 19


< Less than
>= Greater than or equal to
<= Less than or equal to

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

Subject: Java Script Notes Print Date: [16/Oct/24], Page 3 of 19


>> Right Shift
>>> Zero-fill right shift
6. String Operators
Use: These Operators are used with Strings.
Operator Meaning
+ Concatenation
+= Concatenation Assignment
7. Conditional (Ternary) Operator
Use: This operator assign a value based on a condition.
Operator Meaning
?: Condition ? expression1 : expression2
Variable = Condition ? expression1 : expression2

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.

Subject: Java Script Notes Print Date: [16/Oct/24], Page 4 of 19


10. Delete Operator
Use: It removes a property from an Object.

Subject: Java Script Notes Print Date: [16/Oct/24], Page 5 of 19


11. Void Operator
Use: It evaluates an expressions and returns undefined.
12. Spread and Rest Operator
Operator Meaning
Spread ( … ) is used to expand an array or object.
Rest ( … ) is used to condense multiple elements into an array.

Subject: Java Script Notes Print Date: [16/Oct/24], Page 6 of 19


Give syntax of and explain for-in loop in JavaScript with the help of suitable example.
 For-in loop is used to iterate over the enumerable properties of an object.
 It iterates over the keys (Property Names) of an object or an array.
 It allow you to access each key and its corresponding value.
 It is easy to accessing or manipulating object properties.
Syntax:-
For ( variable in object )
{
//code block to be executed
}
 Here, variable : is used to store the key (Property Name) and
object : whose enumerable properties will be iterated.
Subject: Java Script Notes Print Date: [16/Oct/24], Page 7 of 19
Subject: Java Script Notes Print Date: [16/Oct/24], Page 8 of 19
Subject: Java Script Notes Print Date: [16/Oct/24], Page 9 of 19
Enter The Numbers using prompt dialog and display addition of digits in message box.

Subject: Java Script Notes Print Date: [16/Oct/24], Page 10 of 19


EXPRESSIONS.
 Expression is a statement which is form by the combination of operands and operators.
 Expression is any valid unit of code that resolves in to a value.
 Expression allow to manipulate the values and execute logic.
 Expressions are evaluated to produce the value.
 Operators are meaningful symbols to perform meaningful operations on operands.
 Operands are either variable or constant on which operator perform its operations.
 Operator perform operations on operands and produce new value.
 Expression once completely evaluated then it produce single value.
 Expression may be simple or complex.
 Multiple simple expressions are combine together which forms complex expression.

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

Subject: Java Script Notes Print Date: [16/Oct/24], Page 11 of 19


 Keywords : JavaScript uses certain keywords that hold a special meaning and are
reserved by the language.
o They act as primary expressions.
o this : Refers to the current object or execution context (function or method).
Example : this.propertyName
o super : Refers to the parent object in class inheritance.
Example: super()
o null : Represents an empty or non-existent value.
o true and false : Represent boolean values.
 Variable Reference : A variable name can be used as a primary expression that refers to
a stored value.
o let x = 10; x // This is a variable reference, resolving to 10
 Grouping Operator (()) Parentheses can be used to group expressions and control their
evaluation order. The grouping operator is also considered a primary expression.
o (3 + 5) * 2 // The sum (3 + 5) is grouped and evaluated first
Object Initializer.
 Object Initializer is shorthand method to create object using literal syntax.
 This is most convenient method to define and initialize these data structure without
explicitly call constructors like new Object().
 Object initializer allow you to create objects using a key-value pair structure enclosed
within curly brace { }.
 Sometimes it is also called as Object Literals.
 Syntax:
Var newObject = {
Key1 : value1,
Key2 : value2,
….
KeyN : valueN
};
 Example:

Subject: Java Script Notes Print Date: [16/Oct/24], Page 12 of 19


 Property Shorthand: When the key name and variable name are the same.
 Method Shorthand : When method can be define without function keyword.

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:

 Objects and Array Initializers in Complex Expression :


o You can also use object and array initializers with more complex expressions like
inside nested within other objects.

Subject: Java Script Notes Print Date: [16/Oct/24], Page 14 of 19


Function Initializer.
 You can also create function using function initializer.
 It is also known as function expression.
 This allow you to assign a function to a variable or pass it as an argument.
 Example

Subject: Java Script Notes Print Date: [16/Oct/24], Page 15 of 19


Property Access Expression:
In JavaScript, a Property Access Expression is used to
 Retrieve or set the value of an object's property.
 There are two main ways to access properties in JavaScript:
 Dot Notation
o Dot notation requires the property name to be a valid identifier (no spaces or
special characters).
o Dot notation is simpler and more readable when dealing with straightforward
property names.
o Syntax: object.property
o 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:

Subject: Java Script Notes Print Date: [16/Oct/24], Page 16 of 19


Invocation Expression
 In JavaScript, an invocation refers to the process of calling or executing a function.
 Here are some common ways functions are invoked in JavaScript:
o Regular function invocation:
o Method invocation:
o Constructor invocation (with the new keyword):
o Function call using call() or apply():
 Regular function invocation:
o When you call a function using parentheses (), it gets executed.
o Example:

Subject: Java Script Notes Print Date: [16/Oct/24], Page 17 of 19


 Method invocation:
o Functions can be methods (i.e., properties of an object).
o To invoke them, you call them using the object's name.
o Example:

 Constructor invocation (with the new keyword):


o When you invoke a function as a constructor (using new), it creates a new object.
o Example:

Subject: Java Script Notes Print Date: [16/Oct/24], Page 18 of 19


 Function call using call() or apply():
o Functions can be invoked with a specific this context using call() or apply().
o Example:

Subject: Java Script Notes Print Date: [16/Oct/24], Page 19 of 19

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy