Expression and Precedence

Class:BCOM IIyr

Subject:WebDesigning
Subject Type:OEL
Asst Prof.Manju Kumawat

1. Expression 

An expression in JavaScript is a combination of values, variables, and operators that is evaluated to produce a single value.

Example

5 + 3

Explanation:
This expression evaluates to 8.

Another example:

let result = x > 10;

Here, x > 10 is an expression that produces true or false.


2. Operator Precedence 

Operator precedence is the rule that determines which operator is evaluated first when an expression contains more than one operator.

Example

let value = 10 + 5 * 2;

Explanation:
Multiplication (*) has higher precedence than addition (+), so:

10 + (5 * 2) = 20

Using parentheses:

let value = (10 + 5) * 2;

Now the result is:

30

0 comments:

Post a Comment