1. Variables
JavaScript is a weakly typed language, there is no type variable, that is, a variable can store any type of data
Define variables to be defined with Var
Example: Var x=3; var x= "string";
Note: Both single and double quotes in JavaScript can define a string, undefine is a constant value that is not initialized by a variable in JS
2. Statements
Roughly the same as Java
Note: null is false in JavaScript, non-null is True
3. Functions
JavaScript does not have a type, the function does not involve return type and parameter type
Use function to define functions
Called in <script></script> when the function is called
Note:<script></script> is the code range for JavaScript
Example: General functions
<script> function Show (x, y) { }</script>
Dynamic functions: That is, parameters and function bodies can be passed in as variables.
var New Function("x", "Y"; " Alert (x+ "" +y); ");
Anonymous functions: Can be used as a way to handle an event
var function (){}
Note: A function can also have a return value, and if a function without () is assigned a value, it is the processing of the assigned function, and if so, the return value of the assigned function.
You can use functions to create objects, object-oriented thinking, code examples:
<script> function person (name, age) { this. Name = name; this. Age = Age ; } var New Person ("Lisi"); = "Boy" function() { alert ("Walk"); } </script>
Note: There are two ways to invoke the top object's own property, which can be called through., or by p["property name", what is the difference between the two?
P.name This method is only suitable for a single call, p["name"] this way can implement bulk call
For example, p has more than one property, the property name of P is read out in an array m, when the bulk call can be used p["m[i]" this way to achieve
JavaScript basic Syntax