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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:41:06+00:00 2026-06-14T10:41:06+00:00

Is it possible to pass a string into an if statement as a means

  • 0

Is it possible to pass a string into an if statement as a means to create dynamic if statements? A simplified example would be:

var condition = "bool == true";
if(condition) console.log('It is true!);

Of course the example above does not work, because it always returns true, because the string has content. Is there some way to inject to contents of condition into the if statement as actual parameters though? The condition needs to be in string format because in a real world application, the condition will be pulled out of an existing HTML block using a regular expression and is therefore returned in string format.

Vanilla javascript only please.

  • 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-14T10:41:08+00:00Added an answer on June 14, 2026 at 10:41 am

    eval would work, but it’s dodgy.

    How confident are you that these strings are always going to be valid javascript?

    What happens if someone tricks your app into putting

    location.replace('http://stackoverflow.com');
    

    (or worse) into that HTML block?

    If you find yourself needing to use eval it generally means you should rethink your approach.

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

Sidebar

Related Questions

Is it possible to pass over a string, finding the white spaces? For example
Is that possible to pass variable into regular expression pattern string in jquery (
Is it possible to pass a query string into a style sheet and if
Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) Hy,
Possible Duplicate: How to Pass String to another forms from one form in c#
Is it possible to pass *args to string.format? I have the following function: @classmethod
In VB.NET, it is entirely possible to pass an integer as a string parameter
I want a way to pass a string statement from one base class to
Possible Duplicate: how to copy char * into a string and vice-versa I have
Possible Duplicate: How do I parse a string representing a nested list into an

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.