Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript

What is the toExponential() method in JavaScript?

Umme Ammara

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The toExponential() method in JavaScript converts a number into the exponential notation in string format. If the method is invoked on an object that is not a number, a TypeError occurs.

Syntax

The toExponential() method is declared as shown below:

Parameters

The toExponential() method takes a single optional parameter x.

  • If x is not within the range 0-100, a RangeError occurs.

  • If x is not specified, the default value is the number of digits required to specify the number.

Return value

The toExponential() method returns a string that represents the number as an exponential notation.

Example

The following code shows the use of the toExponential() method in JavaScript:

//Example 1
var num = 1.25;
console.log(num.toExponential());
//Example 2
var num2 = 1.234567;
console.log(num2.toExponential(3));

RELATED TAGS

javascript

CONTRIBUTOR

Umme Ammara
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring