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 3319446
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:49:32+00:00 2026-05-17T22:49:32+00:00

I have stumbled across a bit of code that I was hoping someone could

  • 0

I have stumbled across a bit of code that I was hoping someone could explain to me.

This is used in the context of jqGrid.

onSelectRow: function(id){ 
     if(id && id!==lastsel){ 
          jQuery('#rowed3').jqGrid('restoreRow',lastsel);
          jQuery('#rowed3').jqGrid('editRow',id,true); 
          lastsel=id; 
     } 
}, 

Why use logical operators on a string in javascript as shown above? Is this simply a bug or is there some functionality here that I dont understand?

Code is taken from http://trirand.com/blog/jqgrid/rowedex3.html

Full example http://trirand.com/blog/jqgrid/jqgrid.html > Row editing > Using events

  • 1 1 Answer
  • 1 View
  • 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-05-17T22:49:33+00:00Added an answer on May 17, 2026 at 10:49 pm

    The variables should be numeri, though, the conditional would work either way.

    if(id && id !== lastsel)


    1. The first id is saying that it must have a value. The value also has to be truthy. A value is truthy if it is not falsy, which means it just can’t be one of the following (borrowed from 11heavens.com):

      • false
      • null
      • undefined
      • The empty string ''
      • The number 0
      • The number NaN (NaN is of type number)

      Note: You will see the same kind of comparisons to true elsewhere in JavaScript, specifically for/while loops:

      /*1*/ while(id){...} // while id is true, do something
      /*2*/ for(;id;){...} // same thing, without the incrementation or variable definition
      

    2. The second part is saying the id can’t be equal the lastsel, which is the last id that was used. !== is special in JavaScript meaning it must compare value and type, whereas != just compares value:

      • a == b : value of a equals value of b
      • a != b : value of a does not equal value of b
      • a === b : value of a equals value of b and type of a equals type of b
      • a !== b : value of a does not equal value of b and type of a does not equal type of b

    Edit


    Additonally, it might help to think of the expression if you saw it in parentheses:
    if( (id) && (id !== lastsel) )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that parses through an html file and I stumbled across
I have stumbled across some code that is adding strings to a List but
I've just stumbled across this and I'm a bit puzzled. I have an out-of-the-box
I have stumbled across this website : http://www2.research.att.com/~bs/C++0xFAQ.html#lambda where they explain lambda functions .
I've never stumbled across this before, but I have now and am surprised that
I have stumbled across this insane behavior where image.onload gets fired multiple times instead
In a code review today, I stumbled across the following bit of code (slightly
I have always used (typeof variable === function) and I stumbled across jQuery.isFunction() and
I have to maintain some legacy (MS) C++. In that codebase, I stumbled across:
Recently I stumbled across mongoDB, couchDB etc. I am hoping to have a play

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.