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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:51:41+00:00 2026-06-06T13:51:41+00:00

test = function(x){ if ( some conditions ) { return true; } else {

  • 0
test = function(x){   
    if ( some conditions ) { return true; }
    else { return false; }
}


if (test(y)) {document.write("You have done this before!")​}​;​

console.log("Checked!");

The intention is to check if the user performed some action in the past. These are just mock up codes that do not really reflect what I am actually doing though.

Question:

I am relatively new to node.js so please forgive me if this sounds trivial. Suppose test(y) is true. Can I be sure that the console.log will be executed after the document.write? Even if test(y) takes a long time to run?

In other words, I need “if (test(y))…” to be blocking. I understand that passing a function as an argument, e.g. setInterval(test(y),100); can be async and non-blocking. But what about “if(test(y))…”?

  • 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-06T13:51:43+00:00Added an answer on June 6, 2026 at 1:51 pm

    NodeJS has both synchronous (blocking) and asynchronous (non-blocking) functions. (More accurately: The functions themselves are always “blocking” but a whole class of them start something that will complete later and then return immediately, not waiting for the thing to finish. Those are what I mean by “non-blocking.”)

    The default in most cases is asynchronous (and they accept a callback they call when the thing they’ve started is done); the synchronous ones tend to have names ending in Sync.

    So for example, exists is asynchronous (non-blocking), it doesn’t have a return value and instead calls a callback when it’s done. existsSync is synchronous (blocking); it returns its result rather than having a callback.

    If test is your own function, and it only calls synchronous functions, then it’s synchronous:

    function test(x) { // Obviously a nonsense example, as it just replicates `existsSync`
        if (existsSync(x)) {
            // The file exists
            return true;
        }
        return false;
    }
    
    // This works
    if (test("foo.txt")) {
        // ...
    }
    

    If it calls an asynchronous function, it’s asynchronous, and so it can’t return a result via a return value that can be tested by if:

    // WRONG, always returns `undefined`
    function test(x) {
        var retVal;
    
        exists(x, function(flag) {
            retVal = flag;
        });
    
        return retVal;
    }
    

    Instead, you have to provide a callback:

    function test(x, callback) {
    
        exists(x, function(flag) {
            callback(flag);
        });
    }
    
    // This works
    test("foo.txt", function(flag) {
        if (flag) {
            // ...
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added some animation using jquery but it's not working: $('.test-container').click(function(){ $(this).css('background-color', 'rgb(119,
I have some test class TestKlass = (function() { function TestKlass(value) { this.value =
So given this input string: =?ISO-8859-1?Q?TEST=2C_This_Is_A_Test_of_Some_Encoding=AE?= And this function: private string DecodeSubject(string input) {
I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){
function test(){ if(true){ var a = 5; } alert(a); } test(); I keep getting
I've done a million if and foreach's in scripts before, but this one I
I have a function that pulls articles records from an MSSQL database. Some are
I am writing a function which has many return points (depending on what conditions
Assume i have a private routine that performs some calculation: private function TCar.Speed: float
Why isn't my code around the test function in Object RegExp working the same

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.