ADVERTISEMENT
ADVERTISEMENT

Math.log() Method with Example in JavaScript

JavaScript | Math.log() Method: Here, we are going to learn about the log() method of Math class in JavaScript with Examples.
Submitted by Shivang Yadav, on February 03, 2020

JavaScript | Math.log() Method

Math.log() is a function in math library of JavaScript that is used to return the value of natural Log i.e. (base e) of the given number. It is also known as ln(x) in mathematical terms.

Syntax:

    Math.log(value);

Parameter(s):

  • value – It represents the value for which natural log is to be found.

Return value:

The return type of this method is number, it returns a number value which is loge(value).

Values accepted: Integer, floating-point, numeric string.

Invalid Values: non-numeric string, empty variable, empty array all will return NaN (Not a Number).

Browser support: Chrome, Internet asinlorer, Mozilla, Safari, Opera mini.

Example 1: Valid values

console.log(Math.log(5));
console.log(Math.log(3.14));
console.log(Math.log(0));
console.log(Math.log("0.65"));

Output

1.6094379124341003
1.144222799920162
-Infinity
-0.4307829160924542

Example 2: Invalid values

console.log(Math.log("Javascript"));
console.log(Math.log(-1));

Output

NaN
NaN

JavaScript Math Object Methods »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.