1

The following statement works fine but jshint doesn't accept it.

My question is "Will this syntax still be valid in the future of javascript ?".

If it is not a matter of concern, how to configure jshint to ignore it ?

function(a){ 
   return (a === 'y'|'x'|'z') ? a : 'x'; 
   // return a if its value is x, y or z, default it to x otherwise
}

-- UPDATE --

!! Please Ignore this !! Actually this was not working fine. Your are not supposed to use bitwise operator on string except for very specific case and when you know what you are doing :p

svassr
  • 5,538
  • 5
  • 44
  • 63

2 Answers2

2

I think that bitwise operators will be still valid in future version of JS, those are basic operator used for lot of programming languages. They were introduced in first version of ECMA and seems to will be included in future versions as ECMA 6 or 7.

You can turn off the jslint warning by setting this on the top of the file:

/*jshint bitwise: true*/

Check out the documentation.

ianaya89
  • 4,153
  • 3
  • 26
  • 34
  • 1
    @Bergi No, I am not but is what I think. If I am not wrong when you operate with bitwise on strings, JS cast those strings to numbers so I don't have any reasons to believe why they could remove the support. – ianaya89 Dec 16 '14 at 20:06
  • 1
    I'm not talking about support of bitwise operators, I said that you don't want to use them on the strings `'x'`, `'y'`, `'z'`. Yes, they would be casted to numbers, and then the OP's expression is exactly the same as `a === 0`. Which is surely not what he intended. – Bergi Dec 16 '14 at 20:12
  • 1
    @Bergi I don't now what exactly he expects, I am trying to help him in what he specify: an issue about jslint – ianaya89 Dec 16 '14 at 20:16
  • 2
    Please no longer worry I was wrong usinng that on strings indeed. Testing it frther I realized it was not working that well. Sorry about that. Anyway thanks for the resources @ianaya – svassr Dec 16 '14 at 20:29
0

!! Please Ignore this !! Actually this was not working fine at the beinning.

Your are not supposed to use bitwise operator on string except for very specific case and when you know what you are doing :p

What I was trying to achieve was something like this.

function test(a){
   return (['x','y','z'].indexOf(a)>=0 ? a : 'x'); 
} 
document.write( test('x') + ', ' ); 
document.write( test('y') + ', ' ); 
document.write( test('z') + ', ' ); 
document.write( test('w'));

And this has noting to do with bitwise operator though.

Sorry for this misleading post.

svassr
  • 5,538
  • 5
  • 44
  • 63