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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:38:38+00:00 2026-05-10T20:38:38+00:00

Can I convert a string representing a boolean value (e.g., ‘true’, ‘false’) into an

  • 0

Can I convert a string representing a boolean value (e.g., ‘true’, ‘false’) into an intrinsic type in JavaScript?

I have a hidden form in HTML that is updated based on a user’s selection within a list. This form contains some fields which represent boolean values and are dynamically populated with an intrinsic boolean value. However, once this value is placed into the hidden input field it becomes a string.

The only way I could find to determine the field’s boolean value, once it was converted into a string, was to depend upon the literal value of its string representation.

var myValue = document.myForm.IS_TRUE.value; var isTrueSet = myValue == 'true'; 

Is there a better way to accomplish this?

  • 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-10T20:38:38+00:00Added an answer on May 10, 2026 at 8:38 pm

    Do:

    var isTrueSet = (myValue === 'true'); 

    using the identity operator (===), which doesn’t make any implicit type conversions when the compared variables have different types.

    This will set isTrueSet to a boolean true if the string is "true" and boolean false if it is string "false" or not set at all.

    For making it case-insensitive, try:

    var isTrueSet = /^true$/i.test(myValue); // or var isTrueSet = (myValue?.toLowerCase?.() === 'true'); // or var isTrueSet = (String(myValue).toLowerCase() === 'true'); 

    Don’t:

    You should probably be cautious about using these two methods for your specific needs:

    var myBool = Boolean("false");  // == true  var myBool = !!"false";  // == true 

    Any string which isn’t the empty string will evaluate to true by using them. Although they’re the cleanest methods I can think of concerning to boolean conversion, I think they’re not what you’re looking for.

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

Sidebar

Ask A Question

Stats

  • Questions 149k
  • Answers 149k
  • 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
  • Editorial Team
    Editorial Team added an answer So you could wrap the critical parts in try/ catch… May 12, 2026 at 9:29 am
  • Editorial Team
    Editorial Team added an answer You can try including cmath instead, and using static_cast<double(*)(double)>(std::log) (cast… May 12, 2026 at 9:29 am
  • Editorial Team
    Editorial Team added an answer You can use the ScriptManager in the template master to… May 12, 2026 at 9:29 am

Related Questions

Can I convert a string representing a boolean value (e.g., 'true', 'false') into an
I'm looking to convert a string of html entities specifying ASCII codes (ie: &#97;)
I have a device that supports 4-color graphics (much like CGA in the old
I want the shortest possible way of representing an integer in a URL. For
I am writing a simple program, which is trying to find next palindrome number

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.