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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:57:42+00:00 2026-05-30T19:57:42+00:00

I opened a js file that I wrote a while back and although it’s

  • 0

I opened a js file that I wrote a while back and although it’s working, I thought I spotted an error. (JS is not my primary language)

I had this:

if( myvar = fieldval.match(mypattern))
  {
     //Do Stuff
  }

So I think I get it. Is this a correct statement?:
A javascript assignment operation evaluates to the value being assigned.

I tested on w3schools

<script type="text/javascript">
var str="The rain in SPAIN stays mainly in the plain"; 
var patt1=/ain/gi;
var test
document.write(test=str.match(patt1));
</script>

and it writes “ain,AIN,ain,ain” where I might have expected it to write “true” or not to write at all because boolean true is not a string. Is my line of thought and then ultimate conclusion correct. (I ask about my line of thought on this because I do not have a lot of formal CS training.)

  • 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-30T19:57:44+00:00Added an answer on May 30, 2026 at 7:57 pm

    It is a correct statement. The new value of myvar is tested:

    if ( myvar = fieldval.match(mypattern) )
    

    When the String.match method cannot find a match, it returns null. !!null === false, so the if-block is not evaluated. When any non-empty match is found, the condition is true, and the block is evaluated.

    In this case, it is very likely that the if-statement is correct, and that the following is intended:

    if ( (myvar = fieldval.match(mypattern)) !== null )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just think that when I opened my file then when I want to write
What translation occurs when writing to a file that was opened in text mode
Recently I opened a .dll file produced by Visual Studio 9 while compiling a
With python inotifyx, do I have to remove watch and close opened system file
I'm Using FILE * F opened in _sfopen () I'm reading from the file
I'm looking to call a subprocess with a file descriptor opened to a given
How can I find out the size of a file I opened with an
I'm using the PHP Eclipse. When a XML file is opened, Eclipse doesn't seem
Is there a way to check if a file has been opened by ReWrite
When sockets are created or files are opened/created in C, is the file descriptor

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.