svassr
svassr

Reputation: 5668

Syntax matter. Conditional statement

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

Upvotes: 1

Views: 73

Answers (2)

svassr
svassr

Reputation: 5668

!! 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.

Upvotes: 0

ianaya89
ianaya89

Reputation: 4243

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.

Upvotes: 2

Related Questions