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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:47:40+00:00 2026-06-06T01:47:40+00:00

I have a function that returns a value that can be true if the

  • 0

I have a function that returns a value that can be true if the condition is met and false if not, but the function can also return a string message in case of an error.

I need to differentiate between the true/false boolean values under normal conditions without mistaking the string value for either one. My strategy is to use a parseBoolean() function that will return a true Boolean-typed true/false value when passed a boolean input, but a “falsy” value that isn’t a Boolean-typed false when passed a string.

Example

function validate(kkk)
{
  //... some check that validates 
  return true;
  //... some check that doesn't validate
  return false;
  //... failure - return explanation
  return 'Error Message jjjjjjjj';
}

function usingit(data)
{
  if(parseBoolean(validate(data)) != false)
  {
    /// the value is Boolean true
  }
  else
  {
    if(parseBoolean(validate(data)) === false)
    {
      /// the value is Boolean false
    }
    else
    {
      /// the value is false but not of a Boolean type 
      /// so we will display it as the error message text.
    }
  }
}

…but I haven’t figured out how to create a parseBoolean() function that behaves this way. Any ideas?

  • 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-06T01:47:41+00:00Added an answer on June 6, 2026 at 1:47 am

    According to this:

    @Esailija Why no sense? If it is true return a true, if it is false
    return false, if it is ‘somestring’ also return false. Get it? –
    Registered User 31 secs ago

    You want

    function parseBoolean(value) {
        return typeof value == "boolean" ? value : false;
    }
    

    But this obviously won’t pass the test of doom.


    This code passes all your tests:

    function parseBoolean(bool) {
        return typeof bool == "boolean" ? bool : 0;
    }
    
    if( parseBoolean('anystring') == false ) {
        alert("");
    }
    
    if( parseBoolean('anystring') !== false ) {
        alert("");
    }
    
    if( parseBoolean(true) ) {
        alert('');
    }
    
    if( !parseBoolean(false) ) {
        alert('');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that returns TRUE or FALSE or Test_operation , and I
I have a function that returns the highest value of an attribute in an
I have a scalar value function that returns a varchar of data containing the
We have a table value function that returns a list of people you may
I have a function that might fail, so the value it returns needs to
I have a function, that returns the next higher value of a Dictionary-Keys-List compared
I have a function that returns two values in a list. Both values need
I have a function that returns log10 values. On converting them to normal numbers,
I have a function h(n) that returns values for each integer 1 =< n
I have a function that uses out parameters to return multiple values to the

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.