Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript or operator not working

var strExt  = GetAttributeFromItemTable(itemTable, "Ext", "FileType");

I did a alert for strExt and it resolves. if (strExt!='wav') { // this works }

if (strExt!='wav' || strExt!='mp3')
{
// this does not work.
}
like image 674
Moni Nunu Avatar asked Mar 17 '11 21:03

Moni Nunu


People also ask

What does || do in JavaScript?

The OR || operator does the following: Evaluates operands from left to right. For each operand, converts it to boolean. If the result is true , stops and returns the original value of that operand.

What does the || operator do?

The logical OR operator ( || ) returns the boolean value true if either or both operands is true and returns false otherwise.

Is not Working JavaScript?

Open your page in a browser, then open the developer tools. In Chrome on Windows, it's ctrl+shift+i . If you are including an external JavaScript file, check for 404 errors in case the path to your file is incorrect. Check for any JavaScript errors that appear in the console.


1 Answers

Your logic is flawed:

if your variable strExt was equal to 'wav' it would not be equal to 'mp3', and versa-visa.

Please explain your desired results more clearly.

I think what you're trying to say is something like (neither 'wav' nor 'mp3'):

if ( !( strExt == 'wav' || strExt == 'mp3' ) )

which is logically equivalent to (not 'wav' and not 'mp3'):

if ( strExt != 'wav' && strExt != 'mp3' ) )
like image 110
zzzzBov Avatar answered Oct 14 '22 21:10

zzzzBov