DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Join us tomorrow at 1 PM EST: "3-Step Approach to Comprehensive Runtime Application Security"
Save your seat
  1. DZone
  2. Coding
  3. JavaScript
  4. Uncaught RangeError: Maximum Call Stack in JavaScript

Uncaught RangeError: Maximum Call Stack in JavaScript

Anyone who's worked with JavaScript knows its error reporting can be painfully vague. In this post, we go over a ways to prevent JS errors.

Robin Jangu user avatar by
Robin Jangu
·
Nov. 02, 18 · Tutorial
Like (6)
Save
Tweet
Share
8.20K Views

Join the DZone community and get the full member experience.

Join For Free

Errors occur where you least expect them, JS developers face this nemesis on a daily basis.

There are two ways to get these wonderful error messages:

1) Non-Terminating Recursive Functions

Browsers allocate memory to all data types. Sometimes calling a recursive function over and over again causes the browser to send you this message as the memory that can be allocated for your use is not unlimited.

There is nothing more painful for a coder than a non-terminating function or a method of recursion that tends to get stuck in an infinite loop.

Be thoughtful while calling functions and use dry runs to prevent infinite loops.

Maximum call stack gets overflow and washes away your hopes of running the code correctly.

var a = new Array(4294967295);  //OK
var b = new Array(-1); //range error

var num = 2.555555;
document.writeln(num.toExponential(4));  //OK
document.writeln(num.toExponential(-2)); //range error!

num = 2.9999;
document.writeln(num.toFixed(2));   //OK
document.writeln(num.toFixed(25));  //range error!

num = 2.3456;
document.writeln(num.toPrecision(1));   //OK
document.writeln(num.toPrecision(22));  //range error!

2) Out of Range

If someone asks you what your name is, you won’t reply ‘2000 yrs.’

var num = 1;
try {
     num.toPrecision(500);  //no can't have 500 significant digits
    }
catch(err) {
     document.getElementById("mylife").innerHTML =err.name;
           }

Certain functions in JavaScript have ranges of inputs that you can give. Always be careful with these ranges. Sometimes while coding we use functions that, in the end, go out of range while performing tasks. These errors can be easily tackled if you keep track of the ranges of variable types used.

While browsers like Chrome will give error notifications, IE will crash.

It should be a priority to check the valid input ranges.

Examples:

Number.toFixed(digits) 0 to 20

Number.toPrecision(digits) 1 to 21

Number.toExponential(digits) 0 to 20

Null is not 0

Hopefully, this blog will help coders a bit.

If you've experienced these types of errors, leave a comment and tell us how you got around them!

JavaScript

Published at DZone with permission of Robin Jangu. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Differences Between Site Reliability Engineer vs. Software Engineer vs. Cloud Engineer vs. DevOps Engineer
  • Top 10 Secure Coding Practices Every Developer Should Know
  • Load Balancing Pattern
  • Better Performance and Security by Monitoring Logs, Metrics, and More

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: