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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:53:25+00:00 2026-06-12T22:53:25+00:00

I wrote a simple extension method. Number.prototype.toMillion = function(){ if(!Number.isNaN){ return this/1000000; } }

  • 0

I wrote a simple extension method.

Number.prototype.toMillion = function(){
 if(!Number.isNaN){
   return this/1000000;
 }
}

987654321.toMillion() raises:

SyntaxError: Unexpected token ILLEGAL

But (987654321).toMillion() works.

So my question is: what’s the difference between 987 and (987)?

Just FYI:

typeof(987) => returns "number"

And

typeof((987)) still returns "number"
  • 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-12T22:53:27+00:00Added an answer on June 12, 2026 at 10:53 pm

    How would the parser know that the part following the . character is meant to signify a method call instead of another part of the number? For example:

    10.1 // This is a number with a floating point
    10.toMillion() //How does it know that this shouldn't be part of the number?
    

    For that reason, you can’t call methods on numeric literals. By placing the literal in parentheses (the grouping operator), the runtime will evaluate the contained expression and apply the method to the result of that evaluation.

    The grouping operator removes the ambiguity of the . character.


    Update

    Following some thought and some investigation through the spec, there is a good reason to not allow the use of a lookahead to determine whether what follows the . character is part of the number or a property identifier.

    As @CygnusX1 mentioned in the comments, you would have though that the two situations (. followed by a digit and . followed by a non-numeric character) could be differentiated by the use of a lookahead. Since identifiers can’t start with a number, if a numeric character follows the ., it has to be a number. If a non-numeric character follows the ., it can’t be part of the number. But that’s not quite right.

    There is one situation in which a non-numeric character can follow the . character but still be part of the number:

    console.log(1.e5); // Logs '100000'
    

    The e indicates that what follows is the exponent, and it can be either lowercase or uppercase. For this reason, using a lookahead would have to take into account that if the character following the . is e or E, it could still represent either a method or part of the number. It’s easier to just disallow the use of properties on numeric literals.

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

Sidebar

Related Questions

I wrote a simple function, that makes emacs add matching quotes (so when I
I wrote a simple javascript function to display a progressbar with the help of
Hi I've wrote simple Safari extension to display QR code with url to currently
Hay guys, I've wrote a simple upload method for my pictures class Picture(models.Model): path
I've written an extension method that can take an arbitrary number or OrderBy()'s and
I was trying to write a simple extension method for Color static class which
This should hopefully be a simple one. I would like to add an extension
i wrote simple 3 functions to scrape titles , description and keywords of simple
I wrote simple class that on the start it just increase the value of
I wrote simple load testing tool for testing performance of Java modules. One problem

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.