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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:36:30+00:00 2026-06-13T14:36:30+00:00

The following all expressions in JavaScript are far obvious. var x = 10 +

  • 0

The following all expressions in JavaScript are far obvious.

var x = 10 + 10;

The value of x is 20.

x = 10 + '10';

The value of x in this case is 1010 because the + operator is overloaded. If any of the operands is of type string, string concatenation is made and if all the operands are numbers, addition is performed.

x = 10 - 10;
x = 10 - '10';

In both of these cases, the value of x will be 0 because the - operator is not overloaded in that way and all operands are converted to numbers, if they are not before the actual subtraction is performed (you may clarify, if anyway I’m wrong).


What happens in the following expression.

x = '100' - -'150';    

The value of x is 250. Which also appears to be obvious but this expression somewhat appears to be the equivalent to the following expression.

x = '100' +'150';

If it had been the case then these two strings would have been concatenated and assigned 100150 to x. So why is addition performed in this case?


EDIT :

+'10' + 5 returns 15 and 'a' + + 'b' returns aNaN. Does anyone know why?

  • 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-13T14:36:31+00:00Added an answer on June 13, 2026 at 2:36 pm

    In your case - - is not evaluated first to become equivalent to +. -"150" is evaluated as a number, and so became -150.

    As you can’t subtract a string (NaN), JS then take "100" and make a number, and then it run 100 – -150 which is 250.

    The key is really that you can’t subtract type string, so it converts those strings to numbers.

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

Sidebar

Related Questions

I have the following linq expression pulling all data from my database: var items
I have the following case: All boats have a boat type like shark ,
Hi all I have the following Regx that can't be accepted on the JavaScript
Using regular expressions, I want to remove all instances of a certain value unless
i have JavaScript components, that has following architecture: var MyComponent = function(params) { setup(params);
Which of the following expressions will always precede left to right in all browsers(particularly
I have a following regex expression in javascript var reg = new RegExp(^[(]?[2-9]\d{2}[)]?[\-. :]?[2-9]\d{2}[\-.
I am using the following Expression to select all hyperlinks //a[@href] How can I
All, I need to write a regular expression to perform the following operations replace
i want to submit a form using Ext.Direct and iam following all the guidelines

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.