16
16
17
17
### What does this option do?
18
18
19
- The JSHint ` bitwise ` option is used to disallow the usage of any bitwise operators.
19
+ The JSHint ` bitwise ` option is used to disallow the usage of any bitwise
20
+ operators. In JavaScript the available bitwise operators are ` << ` (bitwise left
21
+ shift), ` >> ` (bitwise right shift), ` >>> ` (unsigned bitwise right shift), ` & `
22
+ (bitwise AND), ` | ` (bitwise OR) and ` ^ ` (bitwise XOR). In the following example
23
+ we are using the bitwise OR operator to round a number down to the closest
24
+ integer which is a relatively common shorthand trick:
20
25
21
26
<!-- -
22
27
{
@@ -25,7 +30,18 @@ The JSHint `bitwise` option is used to disallow the usage of any bitwise operato
25
30
-->
26
31
``` javascript
27
32
/* jshint bitwise: true */
28
- var x = 1 & 2 ;
33
+ var x = 1.2345 | 0 ;
29
34
```
30
35
31
- ### What error messages can it cause or prevent?
36
+ ### When should I use this option?
37
+
38
+ The use of the ` bitwise ` JSHint option will cause an "Unexpected use of '{a}'"
39
+ error, where "{a}" is a bitwise operator, any time a bitwise operator is used.
40
+ If you require the use of bitwise operators for actual program logic then you
41
+ cannot enable this option. However, if you do not need to use such operators and
42
+ want to prevent tricks such as the one shown above, enabling this option is a
43
+ good way to do so.
44
+
45
+ Note that this is an * enforcing* option which means JSHint does not apply it by
46
+ default. If you do not explicitly set this option to ` true ` JSHint will allow
47
+ the use of bitwise operators anywhere in your code.
0 commit comments