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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:52:52+00:00 2026-06-11T22:52:52+00:00

What Javascript language rule leads to the following conversion weirdness? new Date() – 2

  • 0

What Javascript language rule leads to the following conversion weirdness?

new Date() - 2 => number
new Date() * 2 => number
new Date() / 2 => number

but

new Date() + 2 => string

I had thought that the + operator would use the valueOf() method of the Date object to convert it to a number. Like in the following example:

{valueOf: function() {return 1;}} + 2 => number

What is different in the case of a Date?

  • 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-11T22:52:54+00:00Added an answer on June 11, 2026 at 10:52 pm

    After studying the Javascript spec, there is indeed a special case for Date objects in the context of the addition operator:

    http://ecma-international.org/ecma-262/5.1/#sec-11.6.1

    Conversion of a Date object is handled differently than for other objects:

    No hint is provided in the calls to ToPrimitive in steps 5 and 6. All
    native ECMAScript objects except Date objects handle the absence of a
    hint as if the hint Number were given; Date objects handle the absence
    of a hint as if the hint String were given.

    I think I understand the motivation, but as a language rule, this feels quite ugly.

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

Sidebar

Related Questions

I want to use a scripting language(Javascript, PHP) to achieve the following task. 1)I
I am trying to setup the following view on CouchDB { _id:_design/id, _rev:1-9be2e55e05ac368da3047841f301203d, language:javascript,
I have a little doubt about javascript, a new language that I'm studying... I
I'm new of javascript language and I'm trying to create a circle using setOptions
I understand the following property of the javascript language: var bar = 1; var
I've been doing some reading about two (relatively) new concepts in the Javascript language
I have defined the following view: { _id:_design/test, language:javascript, views: { test: { map:
I have the following css rule in my document font-family: Trebuchet MS, Tahoma; but
I wonder if it's possible to write a new language above Javascript VM so
I read that the javascript language has characteristics that assist in the implementation of

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.