JavaScript functions
A function is an event-driven or reusable block of code that executes when it is invoked
JavaScript function syntax
function functionname (parameter list) {Here is the code to execute
return value}
In JavaScript, variables are divided into local variables and global variables
A variable declared inside a JavaScript function is a local variable that can only be accessed inside a function
You can use the same local variable in different functions, because only functions that have declared the variable will recognize it
When the function is finished, the local variable is deleted
Variables declared outside of a function are global variables, and all scripts and functions in a Web page can use it
The life cycle of JavaScript variables
The life cycle of JavaScript variables begins when they are declared
Local variables are destroyed after the function has finished running
Global variables are destroyed after the page is closed
In JavaScript, if you assign a value to an undeclared variable, the variable is automatically declared as a global variable
Study for two days of JavaScript, before the course has not been completed before the completion of a test, found that they are still a knowledge point of omission
Here is the result of the test:
1. Which of the following HTML elements can we place Javascript code in? Your answer: <script>2. What is the correct Javascript syntax for writing "Hello World"? Your answer: document.write ("Hello World") 3. Where is the correct location for inserting javacript? Your answers are available in both the:<body> section and the From the above test, the problem is that the basic content of JavaScript (output, statements, comments, variables, data types, objects, functions, operators, etc.) is very easy for people with a certain program language base (especially C language).
JavaScript Learning Notes (5)