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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:00:01+00:00 2026-05-10T23:00:01+00:00

JavaScript does funky automatic conversions with objects: var o = {toString: function() {return 40;

  • 0

JavaScript does funky automatic conversions with objects:

var o = {toString: function() {return '40'; }}; print(o + o); print((o+1)+o); print((o*2) + (+o)); 

will print:

4040 40140 120 

This is because +, if any of the arguments are objects/strings, will try to convert all the arguments to strings then concatenate them. If all arguments are numbers, it adds them together. * and unary + convert objects to numbers using toString (as well as valueOf, not shown here).

What does JavaScript do for the ++ operator?

  • 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-10T23:00:02+00:00Added an answer on May 10, 2026 at 11:00 pm

    From ECMAScript Language Specification

    11.3 Postfix Expressions

    Syntax

    PostfixExpression :

    • LeftHandSideExpression
    • LeftHandSideExpression [no LineTerminator here] ++
    • LeftHandSideExpression [no LineTerminator here] —

    11.3.1 Postfix Increment Operator

    The production PostfixExpression : LeftHandSideExpression [no LineTerminator here] ++ is evaluated as follows:

    1. Evaluate LeftHandSideExpression.
    2. Call GetValue(Result(1)).
    3. Call ToNumber(Result(2)).
    4. Add the value 1 to Result(3), using the same rules as for the + operator (section 11.6.3).
    5. Call PutValue(Result(1), Result(4)).
    6. Return Result(3).

    This is pseudo javascript code of how postInc works:

    function postInc(a) {   var x = +a; // Converts a to a number, Section 11.4.6 Unary + Operator   a = x + 1;   return x; } 

    Edit: As mikesamuel said: it’s not parseInt. Updated to reflect that.

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

Sidebar

Ask A Question

Stats

  • Questions 60k
  • Answers 60k
  • 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
  • added an answer I just ran a test query and the two statements… May 11, 2026 at 9:29 am
  • added an answer Actually one can activate tracing in the Java Control Panel.… May 11, 2026 at 9:29 am
  • added an answer var a = [1, 4, 5]; var e = a.length--;… May 11, 2026 at 9:29 am

Related Questions

JavaScript does funky automatic conversions with objects: var o = {toString: function() {return 40;
Does javascript coding work better with any particular server language?
In Javascript: How does one find the coordinates (x, y, height, width) of every
A response on SO got me thinking, does JavaScript guarantee a certain endian encoding
Why does this javascript return 108 instead of 2008? it gets the day and
Why does the JavaScript function encodeURIComponent encode spaces to the hex Unicode value %20
Which algorithm does the JavaScript Array#sort() function use? I understand that it can take
Does anybody know a way with JavaScript or CSS to basically grey out a
Does anyone have a library or JavaScript snippet to validate the check digit of
Does the for…in loop in Javascript loop through the hashtables/elements in the order they

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.