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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:53:15+00:00 2026-05-17T21:53:15+00:00

when I try the following: if(myFunction() == 3) { alert(‘its three!’); } my function

  • 0

when I try the following:

if(myFunction() == "3") {
    alert('its three!');
}

my function returns undefined, when I know that it is actually returning 3.
Is this because javascript evaluates the if statement before the function can return a value?

if so how can I do something like this:

var result = myFunction();

// Wait until result is there

if(result == "3") {
    alert("its three!");
}
  • 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-17T21:53:16+00:00Added an answer on May 17, 2026 at 9:53 pm

    What it sounds like is that your javascript code is calling the function before the function or the elements it accesses (ie something in the DOM) have been fully loaded, which is why the function call is returning undefined instead of ‘3’.

    The way to prevent this is to defer calling the function until the DOM has finished loading.

    This is typically done by having the function call in your document.onload() method, which only gets run when the page has finished loading, or by using jQuery’s $.ready() method, which again waits until the page is ready before being run.

    Hope that helps.

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

Sidebar

Related Questions

When I try to debug the following function segment, the execution brakes (jumps out
i want to know if i can access the element that triggers a function
Try the following code: myListener = new Object(); myListener.onKeyUp = function() { if (Key.isDown(Key.CONTROL)
I know its probably possible, but is it practical and doable to try and
I know its probably possible, but is it practical and doable to try and
I try to call a DllImport on the following Alsa function (from the documentation
When I try the following lookup in my code: Context initCtx = new InitialContext();
The following is okay: try { Console.WriteLine("Before"); yield return 1; Console.WriteLine("After"); } finally {
I getting the following error when I try to connect to my server app
We try to convert from string to Byte[] using the following Java code: String

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.