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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:00:39+00:00 2026-05-26T03:00:39+00:00

Just started using jslint to check my javascript code. It indicated I should be

  • 0

Just started using jslint to check my javascript code. It indicated I should be replacing

result = value ? value : defaultValue;

with

result = value || defaultValue;

I thought this was a nice shortcut, and tried applying the principle to method calls on potentially null variables, so instead of:

if (arg) {
    arg.doSomething();
}

I tried:

arg && arg.doSomething();

The latter works fine in the browser, but jslint complains with “Expected an assignment or function call and instead saw an expression.”

Is the last statement bad, wrong, dangerous, or is jslint being overprotective ? Using var dummy = arg && arg.doSomething(); do get the message to go away just seems silly.

  • 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-05-26T03:00:39+00:00Added an answer on May 26, 2026 at 3:00 am

    JSLint should be considering this a warning at best (but then, JSLint doesn’t differentiate warnings from outright errors), definitely not an error — but remember that JSLint is about enforcing Crockford’s coding style standards, which may vary from yours (they certainly vary from mine); you might check out JSHint which offers more control, though I’m not immediately seeing an option for this specific condition.

    Your arg && arg.doSomething() is fine, but be aware that it’s somewhat advanced and you’ll lose some people doing maintenance on your code. I never use it in that way. I do use it in expressions, but not on its own. Whether you use it is up to you, but it’s not dangerous, just somewhat opaque.

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

Sidebar

Related Questions

Just started using this technique and am having strange results on the PC side.
I just started using Python as hobby, so forgive me if this is a
I just started using code contracts in my project. However, I have a problem
I just started using #region / #endregion to organize my C# code. Now it
I just started using resharper and it barks at this generated assemblyinfo.cs file. Reason/Logic
I just started using javascript and I'm missing something important in my knowledge. I
I just started using PrimeFaces and cannot figure what is wrong with my code.
I just started using Git and I want to know if this is the
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I

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.