Home  >  Article  >  Web Front-end  >  How to define two functions in javascript

How to define two functions in javascript

一个新手
一个新手Original
2017-10-14 09:45:281326browse

The first way: It can be called before the definition of function or it can be called after functionAfter definitionCall:

(0) Function call

##

add(1,2) //可以调用

(1) Function definition:

##

function add(x,y) {
       console.log(x+y) ;
    }

(2) Function call

add(1,2)//可以调用
The second way: the function can only be called after the

function is defined.

(1) Definition of function

##

var add2=function (ax,ay) {
        alert(ax+ay) ;
    }
(2) Function call

 add2(1,2)

The above is the detailed content of How to define two functions in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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