JavaScript Operator Precedence & Associativity - JavaScript Tutorial 31
HTML-код
- Опубликовано: 9 сен 2024
- Notes for You:: JavaScript Operator Precedence & Associativity - JavaScript Tutorial 31
Precedence:
- While evaluating a given expression; which operator should be evaluated first before the other is determined by precedence of operator.
- I.e. which operator needs to be given higher precedence than the other ?
Associativity:
- If same operator appears one or more times in an expression, in which direction the specific operator(s) need to be evaluated is determined by associativity of operator.
Ex:
a = 3 * 5 + 4 / 2 + 3 + 20 -10
Precedence order of JavaScript Operators:
1 P: Parenthesis
2 U: Unary
3 M: Multiplicative
4 A: Additive
5 S: Shift
6 R: Relational
7 E: Equality
8 B: Bitwise
9 L: Logical
10 C: Conditional
11 A: Assignment
12 C: Comma
Note:
- Highest precedence is given to parenthesis and lowest precedence is given to comma operator.
- Unary and Assignment operators have right to left associativity, others have left to right associativity.
Example code:
var a = 2 + 2 + 2;
document.write(a); // 6
var b = 2 + 3 * 5;
document.write(b); // 17 not 25
var c = 3 * 5 + 4 / 2 + 3;
document.write(c); // 20
var d = 3 * (5 +4) / 2 +3;
document.write(d); // 16.5
var e = 3 * 5 + 4 / 2 + 3 + 20 -10;
document.write(e); // 30
=========================================
Follow the link for next video:
JavaScript Tutorial 32 - Control Statements in JavaScript
• Control Statements in ...
Follow the link for previous video:
JavaScript Tutorial 30 - Special Operators in JavaScript | JavaScript Special Operators
• Special Operators in J...
=========================================
JavaScript Tutorials Playlist:-
• JavaScript Tutorials
=========================================
Watch My Other Useful Tutorials:-
jQuery Tutorials Playlist:-
• jQuery Tutorials
jQuery UI Tutorials Playlist:-
• jQuery UI Tutorials
Bootstrap Tutorials Playlist:-
• Bootstrap4 Tutorials
=========================================
► Subscribe to our RUclips channel:
/ chidrestechtutorials
► Visit our Website:
www.chidrestec...
=========================================
Hash Tags:-
#ChidresTechTutorials #JavaScript #JavaScriptTutorial
SUBSCRIBE, SHARE & SUPPORT:
ruclips.net/user/chidrestechtutorials
VISIT & LEARN AT FREE OF COST:
www.chidrestechtutorials.com
Sir at 9:24 out of the two operators you evaluated the multiplication operator and division operator have equal precedence. Then how do we know which expression will be evaluated first.
According to BODMAS rule division should be implemented first then multiplication
but you did multiplication first and then division @ 9:24 in the video tutorial.. ..Although your answer is correct .I want you to please elaborate this thanks
very nice video sir!
sir completed 20% javascript tutorials
Awsome
cool vid
Sir ? Java script manje kay?
JavaScript ek scripting language hai