Home > Web Front-end > JS Tutorial > How to use valueOf method

How to use valueOf method

不言
Release: 2021-04-20 14:58:29
Original
23882 people have browsed it

The valueOf method is used to return the original value of the string object. Its usage syntax is "string.valueOf()", and its valueof() method returns a number representing the original value of the specified string object.

How to use valueOf method

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

The valueOf() method in JavaScript is used to return the original value of the string object. It is usually called internally by JavaScript rather than explicitly in the code. In this article, we will take a closer look at the basic usage of the valueOf method.

Basic syntax of valueOf()

string.valueOf()
Copy after login

The valueof() method in JavaScript returns a number that represents the original value of the specified string object.

Let’s take a look at specific examples

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script type="text/javascript">
  var num=213; 
  document.write("Output : " + num.valueOf()+"<br/>");    
  var num=-213; 
  document.write("Output : " + num.valueOf()+"<br/>");
   var num=0/0; 
  document.write("Output : " + num.valueOf());    
</script>
</body>
</html>
Copy after login

The running results are as follows:

How to use valueOf method

##This article ends here. For more exciting content, you can pay attention to other related column tutorials on the php Chinese website! ! !

The above is the detailed content of How to use valueOf method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template