Why () are needed in this Javascript code block?

I understand there are many pitfall in javascript, but I still don’t understand there are any difference between expression a&1 and (a&1) ??

the following code tries covert 11 (10 base) to a string 1101 (2 base)

  • Understanding the Context of Curly Brackets '{}'
  • JavaScript: comma after opening bracket of parameter in syntax example
  • JavaScript regex get all numbers but exclude all between brackets
  • Curly Brakets in Es2015
  • Curly Brackets in Arrow Functions
  • Fix Sublime Text 2 brackets matching with > 28 if()-tests?
  • <script>
    var str = '';
    var a = 11;
    for(var i=0;a;i++){
        str = a & 1 + str; // this doesn't work must rewrite as 
        // str = (a & 1) + str;
        console.log('str = ' + str);
        a >>>=1;
    }
    console.log(str);
    </script>
    

  • What is this JavaScript construct: “ = [y for each …]”
  • get all inner brackets/parentheses
  • use brackets in checkbox name when using php and javascript?
  • JavaScript: comma after opening bracket of parameter in syntax example
  • How does the ~[] construction work in JavaScript?
  • Rules for the use of angle brackets in Typescript
  • One Solution collect form web for “Why () are needed in this Javascript code block?”

    It is because of operator precedence

    The Addition has a higher precedence than Bitwise AND. So when a & 1 + str is evaluated the 1 + str is evaluated first then a & result is evaluated.

    Using Grouping Operator we can change the evaluation order. So when (a & 1) + str is evaluated, contents inside () (a & 1) is evaluated first result + str is evaluated.