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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:13:40+00:00 2026-05-30T08:13:40+00:00

If I write this script : alert(parseInt(123blahblahblah456)); I get the alert with the value

  • 0

If I write this script :

alert(parseInt("123blahblahblah456"));

I get the alert with the value 123

Ideally, shouldn’t the function NOT do anything since it is an invalid integer string?
Similar is the case with parseFloat()

  • 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-30T08:13:41+00:00Added an answer on May 30, 2026 at 8:13 am

    Yes: parseInt() is absolutely meant to work like that; to quote the Mozilla Developer Network entry:

    The parseInt function converts its first argument to a string, parses it, and returns an integer or NaN. If not NaN, the returned value will be the decimal integer representation of the first argument taken as a number in the specified radix (base). For example, a radix of 10 indicates to convert from a decimal number, 8 octal, 16 hexadecimal, and so on. For radices above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.

    If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values. Leading and trailing spaces are allowed.

    It seems that parseInt() is explicitly expecting to take a string and will take the first sequence of numbers (until it encounters an invalid numerical character) and return that as a number of whatever base was specified in the radix parameter.

    Incidentally, to reduce errors when parsing the strings passed to parseInt() remember to use the radix parameter, for example:

    parseInt('123odod24',10); // for base-10
    parseInt('123odod24',16); // for base-16
    

    Reference:

    • parseInt() at the MDC.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JavaScript function, in this function i will write <script type='text/JavaScript' language='JavaScript'>alert('ha')</script>
Not sure this is possible, but looking to write a script that would return
How to implement timeout in this code: Response.Write(@<script language='javascript'>alert('some alert');</script>); Response.Redirect(Request.ApplicationPath); I want to
I am displaying a message in my ASP.NET from code-behind using this: Response.Write(<script>alert('Hello')</script>); When
<script type=text/javascript> alert(message function); function message() { alert(This alert box was called with the
When I run this simple greasemonkey script alert(hello); alert(document.location); document.write(hello); alert(hello); Only the first
I have script like this : $(#addk).bind(click, function(event){ //alert(here!); $(#loader-overlay).show(); $.ajax({ 'async':False, 'type': POST,
Can someone explain why this script throws an exception? $byteArray = @(1,2,3) write-Output (
I'm trying to write a batch script, this script is responsible to launch a
I'm trying to write a python script that packages our software. This script needs

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.