Output statement
<script type= "Text/javascript" >
Alert ("<SCR" + "ipt>");
</script>
Grammatical composition
- Case sensitive;
- The first character must be a letter, an underscore, or a dollar sign ($)
- You cannot use keywords, reserved words, true, false, and NULL as identifiers.
- Variables are loosely typed (any type).
- Define variables with the var operator for example: Var box;
Data type
Learning Essentials:
1. The TypeOf operator------------function: detects the type of variable, and can also detect function and object is necessary.
<script type= "Text/javascript" > var box= ' Li '; Alert (typeof box); Alert (typeof ') </script> --------------------------------------------------------results: String
2. Undefined type--------------Assign values when no assignment is defined
3. Null type--------------only one worth data type, special value NULL, NULL object reference (pointer) typeof operator detection Null returns object
<script type= "Text/javascript" >
var Box1=null;alert (typeof Box1); alert (typeof null); var Box;var car = null;alert (typeof box = = typeof car) </script>
-------------------------------------------------------
Result:object object true
4. Boolean type--------two values false and True
To convert a value to its corresponding Boolean value, you can use the transform function, Boolean (). var hello = ' Hello world! '; var Hello2 = Boolean (hello); alert (typeof hello); above is a display transformation, which is a mandatory conversion. In practical applications, there is also an implicit conversion. For example, there is an implicit conversion in the conditional judgment within the IF condition statement. var hello = ' Hello world! '; if (hello) {alert (' If the condition is true, execute my this one! ‘);} else {alert (' If the condition is false, execute me! ‘);
5. Number type-----------integers and floating-point numbers
Alert (parseint (' 456Lee ')); 456 returning an integral number of parts
Alert (parsefloat (' 0123.400Lee ')); 123.4 returning floating-point numbers
6. String Type
The ToString () method generally does not need to pass arguments, but it can be passed into a string when the value is converted to a literal.
var box = 10;
Alert (box.tostring ()); 10, default output
Alert (box.tostring (2)); 1010, binary output
Alert (box.tostring (8)); 12, octal output
Alert (box.tostring (10)); 10, decimal output
Alert (box.tostring (16)); A, hexadecimal output
PS: If the value has the ToString () method, the method is called and the corresponding result is returned, or "null" or "undeinfed" if it is null or undefined.
7. Type of Object
The object in ECMAScript is actually a set of data and functions. An object can be created by executing the new operator followed by the name of the object type to be created.
var box = new Object ();
JavaScript Learning Note 1