A, js way of introduction
External introduced, the introduction of the first to write external, must be written in the script tags
<script type = "text / javascript " src = "js / day01.js"> head tag
</ script>
Embedded introduction
<script type = "text "> / javascript
; Alert ( 'Hello')
</ Script>
</ head>
linked -js introduced into the tag, with the prefix javascript
<body>
intermediate double quotation marks can not be nested double quotes
<a href =" javascript: alert ( 'hello') ">
click me pop
</a>
</ body>
Two, js variable
js naming convention:
js variables begin with a letter, case sensitive, do not use the key names
camel nomenclature - the first letter lowercase, uppercase funCtion behind the
variable name must be unique
js variable definitions:
var x = 1;
Left the right side of an assignment, code execution from the top down
E.g:
<Script type = " text / JavaScript " > X = " Xiong hello " ; / * "character string" * / Alert (X); / * display defined variables * / var A; A = 12 is ; Alert (A) ; / * undefine no assignment error * / / * the first definition of the assignment * / var C; Alert (C); / * empty type * / var D = null ; Alert (D); / * empty string * / var = E ""; alert(e); </script>
var NUM = 10 ; var STR = " white " ; var In Flag = to true ; var NLL = null ; the console.log ( typeof NUM); the console.log (String (NLL); // output string is not null value
This is the type of data acquisition js
Third, the data type
js several data types
Value type ( Number ): contains integer and floating point;
Type String ( String): string must be double quotes or single quotes;
Boolean type ( Boolean): Only two values true or false;
Undefined type ( Undefined ): designed to determine a no initial value has been created but variable;
Mutual conversion between:
+ Values are operators on both sides, it is again arbitrary string connector
1, converts the string values:
There are a = 3;
a=a.toString()+3;
alert(a);a=33
2, and numeric string conversion, taking plastic float
There are b = 5;
var sum=b.parseInt(8)+4;
alert(sum);sum=8+4=12
NAN:not a number
size:
String -> float; integer variable = parseFloat (string).
Get string between js:
<Script type = " text / JavaScript " > var STR = " the I LOVE you " ; / * Get the character at the specified index = .charAt string variable (index) * / var A = str.charAt ( . 4 ); Alert ( a); / * all uppercase characters in the string * / var B = str.toUpperCase (); Alert (B); / * all lowercase characters in a string * / var C = STR. the toLowerCase (); Alert (C); / * returns the specified string in a position large string, the first letter of eh first occurrence of * / var D = str.indexOf ( " LOVE " ); Alert (D); / * taken from a specified position to the end of the string of * / var E = str.substring ( 2 ); L Alert (E); / * taken from the specified start location to the specified end * / var F = str.substring ( 2 , 6 ); // 2 where to start, 6 intercepts 4, obtained by subtracting 4love, no header trailer Love Alert (F); </ Script>