JavaScript Tutorial: Operator Precedence And Associativity

preview_player
Показать описание

☛ JavaScript Basics Playlist ☚

☛ JavaScript Beyond Basics Playlist ☚
------------------------------------------------------------------------------------

Hey Delightful Programmer,

Enjoy the new video and don't forget to subscribe.

------------------------------------------------------------------------------------

★ Social - FOLLOW ME BELOW ★

☆ If you enjoyed this video, give it a like.

☍ If you know someone who might like it, share it.

☝ Share your thoughts below in a comment.

-~-~~-~~~-~~-~-
Please watch: "JavaScript Switch Statements (Switch and Case)"

☆ If you enjoyed this video, give it a like.

☍ If you know someone who might like it, share it.

☝Share your thoughts below in a comment.
Рекомендации по теме
Комментарии
Автор

1+2*1 is a bad example since it returns 3 no matter what order the operators are executed in. 1+2*3 would be better. And using only the + operator to demonstrate associativity is another bad example since + is a commutative operator in which the order never matters. Another commutative operator is * multiplication. Use instead - minus or / division. For example 3-2-1 is either (3-2)-1=0 or 3-(2-1)=2. But since minus is left-associative (most operators are) the answer to this is 0. Left or right associativity is used to determine the order for operators of equal precedence. Another example of a right-associative operator, besides = assignment, is the power operator which in many languages are written as ^ or **. This means that and not 64. You have good presentation skills but need to prepare better examples.

chapfellow
Автор

hey Hiii,
nice video I have seen this code on MDN but can't understand, please make a video on it


code : console.log(2 * 3 ** 4);
console.log(2 ** 3 ** 4);


How and why answer?

atulcodex
Автор

all of the examples you showed at the beginning produce the exact same result regardless of the operator precedence level which doesn't really demonstrate the point.
(1 + 2) - 1 === 1 + (2 - 1)
(1 + 2) * 1 === 1 + (2 * 1)

sqyou
join shbcf.ru