Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly read EcmaScript specification

I'm interested in "HOW it work" knowledge for JavaScript binary logical operations, but I'm stuck at step interpritation.

So that's description of specs

12.13.3

LogicalANDExpression: LogicalANDExpression && BitwiseORExpression

  1. Let lref be the result of evaluating LogicalANDExpression.
  2. Let lval be ? GetValue(lref).
  3. Let lbool be ToBoolean(lval).
  4. If lbool is false, return lval.
  5. Let rref be the result of evaluating BitwiseORExpression.
  6. Return ? GetValue(rref).

And i read this like:

  1. Take memory for left operand and here will be operation result

  2. Get value of left operand in memory and convert it to boolean

  3. if this boolean is false, return left operand

  4. Else take memory for right operand and here will be... BitwiseORExpression <-- what? Bitwise? for what? why?

I'd would like to clarify this algorithm in more human-readable form for understanding how it works. What is p.1 and p.5, what really is lref and rref, what really is LogicalANDExpression and BitwiseORExpression in that context?

like image 246
Andrew Avatar asked Mar 13 '26 04:03

Andrew


1 Answers

BitwiseORExpression here just refers to the (expression for the) right operand, exactly like LogicalANDExpression refers to the left one as you correctly deduced. What it is depends on the code (or rather its parsed form, the AST) that you are currently evaluating, it could be basically anything and does not need to contain an | operator.

like image 112
Bergi Avatar answered Mar 15 '26 18:03

Bergi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!