Three JavaScript syntax basics-Variables and functions
(a) Declaration and application of variables
Variables in JavaScript are very different from strongly typed languages such as Java and C, although there are strings, numbers, and other data types in JavaScript.
The structure of a variable declaration statement is a VAR reserved word plus an identifier, separated by a space between Var and the identifier.
The structure of an assignment statement is to add an equal sign between the variable and the value that needs to be assigned, for example, the meaning of a=1 is to specify the value of variable a as 1.
Variables can also be assigned at the time of definition, such as Var a=1.
PS: It is a good programming habit to declare before variables are used, which is useful for learning other languages such as Java in the future. Obsessive Compulsive disorder is a good habit.
(ii) Declaration and use of functions
A function is a piece of code that can do a certain function, accept several parameters, and return a result.
Usually in a complex programming, always according to the function to be completed, the program is divided into relatively independent parts, each part of a function, so that the parts are fully independent, the task is single, the program is clear, easy to read and easy to maintain.
A parameter is a value that is passed to or manipulated by a function, whose value can be a constant, variable, or other expression.
A JavaScript function encapsulates a program that may be used multiple times in a program and can be invoked as an event-driven result, thereby implementing a function that is associated with the event driver (emphasis).
Specific as follows "
* Definition of function
Function name (parameter)
{
function body;
return value;
}
* Function Description You can use a variable, a constant, or an expression as a parameter to a function call
* functions are defined by the keyword function
* The definition rules for function names are consistent with identifiers and are case sensitive
* Return value must use return
<! DOCTYPE html> with a JS page</title ><script type= "Text/javascript" >function hello () { var hi; var name=prompt ("What is your name?:", "Doriswowo"); Hi= "Hello" +name+ "!welcome to my space~~"; Alert (hi); document.write (HI);} Hello (); // </script>page content </body>
JavaScript syntax basics-Variables and functions