Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9221149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:30:52+00:00 2026-06-18T03:30:52+00:00

Before anyone jumps in to answer and bash me for asking a silly question;

  • 0

Before anyone jumps in to answer and bash me for asking a silly question; I’m aware of what the not operator does, at least in other languages it should invert a result from true to false and vice versa. The thing I’m stuck on is the strange behavior I get from time to time. I.e. I had this in my code. It’s not doing what I expect it to do.

_checkOnOff: function(inst) {
    return (!$.suggestBox.onOff || !$.suggestBox._get(inst, 'onOff')) ?  false : true;
},

The actual values for the ‘onOff’ variables that I’m dealing with here are 0 and 1. I’m assuming that the ‘!’ operator will reverse them.

However I couldn’t get it to work until I changed the function to explicitly state ‘== 0’ like so…

_checkOnOff: function(inst) {
    return ($.suggestBox.onOff == 0 || $.suggestBox._get(inst, 'onOff') == 0) ?  false : true;
},

Edit: Added info Both $.suggestBox.onOff and $.suggestBox._get(inst, ‘onOff’) will be either 0 or 1.

My question is why didn’t !$.suggestBox.onOff produce true when $.suggestBox.onOff was equal to 0? Is Javascript ! equivalant to the bitwise operator?

Edit: Second attempt

I tried using ‘!!’ like was suggested (to get a bool) and found nothing changed. Here is the code and outputs:

        console.log('val: ' + $.suggestBox.onOff);  // outputs: 0
        console.log('! : ' + !$.suggestBox.onOff);  // outputs: false
        console.log('!! : ' + !!$.suggestBox.onOff);   //outputs: true
        console.log('!!! : ' + !!!$.suggestBox.onOff);   //outputs: false

The output doesn’t change if $.suggestBox.onOff is 1 or 0!!! it’s still false, true, false. What is going on?!

Edit: Third attempt I found out that it has something to do with my variable. I don’t know how, but it has to do with the way that it has been set. Ok, prepare yourselves, what I’m about to tell you, may very well blow your mind and change the way you type on the keyboard. It’s that incredible:

        //this.onOff = 0;
        console.log('this.onOff: ' + this.onOff);   //output: 0
        console.log('! : ' + ! this.onOff);  //output: false
        console.log('!! : ' + !! this.onOff);   //output: true

If I uncomment out the ‘this.onOff = 0’, thereby explicitly assigning this.onOff to a literal, it changes the output to:

  • 0
  • true
  • false

I just found out why. I will write it down in the answer section. Small clue is that it’s the way the variable $.suggestBox.onOff was set.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:30:53+00:00Added an answer on June 18, 2026 at 3:30 am

    It seems that $.suggestBox.onOff is set with "0" as a string, which in JavaScript is always truthy.

    Since "0" is truthy and 0 is falsy, you’d expect 0 == "0" to be false, but it’s not.

    Try the following in your console:

    !! "0"; // true
    !! 0; // false
    0 == "0"; // true
    

    Weird? Yes. Welcome to the awkward world of JavaScript!


    To get around this issue, you should either have $.suggestBox.onOff be an actual number, or convert it on the fly:

    _checkOnOff: function(inst) {
        return !! ( +$.suggestBox.onOff && +$.suggestBox._get(inst, 'onOff') );
    }
    

    Update: Since you pointed out in the comments that you’re setting it by a text value, use this when setting it so that it’s always set as a number:

    $.suggestBox.onOff = +$(this).val();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, before anyone attempts to label this as a duplicate, I am not asking
Before anyone jumps to conclusions as to the nature of this question, I already
Does anyone know how to set the working directory in JavaScript before? Code I
Before I go ahead and write something myself is anyone aware of a library
(Before anyone asks, it's not homework.) Say you have 2 Arrays y0 and y1
(Before anyone asks, this is not homework.) I have a set of workers with
Before anyone close this question or complain... I've been looking all over StackOverFlow site
Before anyone jumps on me, I have found a similar issue here , but
Anyone had this issue where the page quickly jumps to the top before a
Before anyone comments, I must use HSQLDB RDBMS; it's for university java project. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.