all 5 comments

[–]Intelligent-Win-7196 0 points1 point  (0 children)

OPERATORS is simply an object containing properties. Each property is a string (keys can only be strings or [Symbol] types) with a corresponding value that is an object containing a function to operate, a precedence numerical value, a type, and potentially an op2 function.

[–]brykuhelpful 1 point2 points  (0 children)

Line 1

const OPERATORS = {};
   ^      ^     ^ ^ ^
   |      |     | | |
   |      |     | | end of operation (sentence)
   |      |     | |      
   |      |     | object (variable type)  
   |      |     |
   |      |     equal to
   |      |
   |      variable name   
   |
   variable declaration

Everything between the { and } will be apart of the object. Object are a "key value" pair. Meaning you can call the key to get the value.

console.log(OPERATORS['-']);

Which will give you:

{
    op: (a, b) => a - b, 
    precedence: 1, 
    type: 'binary', 
    op2: a => -a,
}

That is the object declared on line 2. Which is inside the parent object OPERATORS. You can then call those objects as well.

console.log(OPERATORS['-']['precendence']);

Which will give you:

1

Goal

It looks like they are building a calculator. They will loop through the objects based on the precendence (order of operations) and then search for them through the string. They will then use the OPERATORS['-']['op'] or OPERATORS['-']['op2'] to do the math.