1: A function definition encapsulates a piece of code with a specific function called a function

2: Classification of functions:

1) From the definition point of view: built-in functions. User-defined functions 2) In terms of parameters: functions with and without parameters 3) in terms of return values: functions with and without return values

3 Definition and call of function with no parameter and no return value

3: Definition format:

Function name () {function body}

5: Call format: function name ()

6: The benefits of defining functions

1) it can control the execution time of code 2) it can improve the reusability of code 3) it can improve the maintainability of code

Defines a function that prints all even numbers between 1 and 100

function printNum(){ for(var i=1; i<=100; i++){ if(i%2===0){ console.log(i); }}} printNum();Copy the code

Defines a function that prints a right triangle

Function printTringle () {for (var I =1; i<=5; I++){for (var j=1; J < = I; J++ +){document.write(' * ')} document. Write (' <br>')}} printTringle ()Copy the code