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

  • Home
  • SEARCH
  • 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 108481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:55:07+00:00 2026-05-11T01:55:07+00:00

If you are doing something like the following: var i = $(‘input[@name=some_field]’); if (i.val()

  • 0

If you are doing something like the following:

var i = $('input[@name=some_field]'); if (i.val() != '' && !(i.val() >=1 && i.val() <= 36) || i.val() == 'OT')) {      i.focus(); } 

is i.val() fast enough to use it multiple times or should you do:

var value = i.val(); 

first and then use value in the if statement, like:

var i = $('input[@name=some_field]'); var value = i.val(); if (value != '' && !(value >=1 && value <= 36) || value == 'OT')) {      i.focus(); } 

…?

  • 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. 2026-05-11T01:55:07+00:00Added an answer on May 11, 2026 at 1:55 am

    This isn’t necessarily a jQuery question but it applies pretty well to most programming languages. And in fact, there’s a lot more to this question than just performance issues.

    One thing to keep in mind is that if you store the value, then there is no possibility that it will change during the execution of your subsequent code. Most of the time, this is what you expect and want. But it is also possible in some circumstances that the call to val() will return a different value, especially if you are looping and doing something that takes any significant time.

    In your particular example, the chances of this occurring are pretty low because it’s only a few calls and not in a looping construct. Given that there are only a few calls, performance likely won’t be a major concern here. But the theory of the point remains – if you want to guarantee that the value doesn’t change, put it in a variable. Since it also gives you the best of the performance considerations, I think this would be a best practice in most cases.

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

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 73k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Yeah, it makes sense if you want both to be… May 11, 2026 at 2:10 pm
  • added an answer They both accomplish the same thing -- code signing. As… May 11, 2026 at 2:10 pm
  • added an answer The 'Cons' value constructor has a single type parameter. Nope:… May 11, 2026 at 2:10 pm

Related Questions

If you are doing something like the following: var i = $('input[@name=some_field]'); if (i.val()
If you are using ASP.NET MVC how are you doing grid display? Rolled your
If you are using HAML and SASS in your Rails application, then any templates
If you are working in PHP (or I guess any programming language) and using
If you are relying on an implementation of Python that has a Global Interpreter
From what I've seen in the past, StackOverflow seems to like programming challenges, such
I am in the process of refactoring our BI layers to make our code
I'm currently rebuilding a specialised ticket system at work (mainly used to support people
Important: This question is getting quite long, if this is the first time you're

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.