Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JavaScript function


May 29, 2021 Article blog


Table of contents


The JavaScript function is similar to Java's approach, allowing you to complete blocks of code for a specific task and try it out directly.

function:

Function classification: Custom functions and system functions

Common system functions

ParseInt ("String"): Converts a string to an integer number

example:

ParseInt ("86a") output is 86

ParseInt ("86a21") output is 86

ParseInt ("a86a") output is NaN


ParseFloat ("String"): Converts a string to a floating-point number

example:

The parseFloat ("34.34") output is a floating-point value of 34.34

isNaN(): Used to check if it is a non-number

IsNaN ("111") outputs false

IsNaN(true) output false

IsNaN ("true") outputs true

IsNaN ("aaa") outputs true

IsNaN ("111a") outputs true

Custom functions

1, define the function

 JavaScript function1

2, call the function

Function calls are generally used in conjunction with form element events, and their format is called

Event name: "Function name ()"

First, call the parameterless function

instance:

function study( ){
        for(var i=0;i<5;i++){
            document.write("<h4>欢迎学习JavaScript</h4>");
        }
    }

Click the button to call study() to execute the code of the function body

<input name="btn" type="button"
   value="显示5次欢迎学习JavaScript"  onclick="study( )" />

Second, call the parameter function

instance:

function study(count){
        for(var i=0;i<count;i++){
            document.write("<h4>欢迎学习JavaScript</h4>");
        }
    }

Click the button to call study (count) to execute the code of the function body

<input name="btn" type="button" value="请输入显示欢迎学习JavaScript的次数"
  onclick="study(prompt('请输入显示欢迎学习JavaScript的次数:',''))" />

That's all you need to know about JavaScript functions.