JavaScript basics
I. Features of JavaScript
Browser scripting language, which can be mixed with HTML code
Superior Cross-platform performance and can be written on Windows.linux
Good security
Good compatibility
Two. Javascrpt has three major learning objectives
Effects
Form validation
Ajax
Three. JavaScript Basic syntax
There are four types of JavaScript usage scenarios
Script tag
<script type= "text/javascript" >
Alert (' Hello ')//alert display content in the page bounce box
<script>
Externally introduced script tag, requires SRC attribute
2.1 Create File 1.js
2.2 Introducing 1.js effects files through the script tag in the main HTML file
<script type= "text/javascript src=" ./1.js></script>
./represents the current directory with absolute path and relative path notation
3. Element Event Properties
<button onclick= ' func () > button </button> <script type= "text/javascript" > function func () {alert (' Button Trigger '); } <script>
The Func () function is triggered by clicking on the button box and clicking the onclick action, which implements the alert () Effect.
href attribute of the 4.a tag
Declare a variable var variable name for example: var a = 1; Declaring a variable is 1
<a href= "javascript:var A=10;var b=10;alert (a+b);" > Connectivity </a>
Four. variables are declarations
The declaration of a variable can be made up of alphanumeric underscores
The first letter cannot be a number.
JavaScript is very strictly case-sensitive
And can't keyword, here's the keyword For example can't make JavaScript built-in function name
Five. notes
Commented content, in the final page display is not visible, easy for developers to see the code description, but also for other people to watch, you can view the Web page source code to watch
Single-line comment//content
Multiline comment/* content */
Six. data type
Classification of data types
Boolean (boolean) string (string) number (numeric Type) object (object) function undefined
The number numeric type, which is shaped and floating in php, is collectively referred to as a numeric type in javascript, so the Nember type contains a shape that also contains a floating point type, and a special Nan with no numeric value.
nan, and any numeric operation, results in a value of Nan.
When any value is compared to nan, the returned result is False. (! = And!==) The returned result is true
When detecting whether a value is nan, you can use the isNaN function
Oject object that contains the Newobject.newarray,null
Seven. Data type Conversion
Data type conversions are divided into forced type conversions and automatic type conversions
1.1 Coercion of type conversions:
There are three conversions of numbers
Parseint: if it is a pure value, the value returned is directly a numeric type,
If the first letter is a number, it is truncated to the first digit that is not the number returned
If the first letter is not a number, return Nan
Parsefloat: the law of transformation and parseint consistent
Number: pure numbers are converted to pure digits, and if there are non-numbers in the middle, return nan directly (true = 1 false = 0)
1.1 Convert to String
string conversion via string, e.g. ' 123 ' after string (123) conversion
1.3 Convert to Boolean Boolean
2.1 Automatic type Conversion Primary if () the contents inside parentheses are automatically converted to true and false
Nan means note a number, which detects whether the Nan type is IsNaN
A string of numbers and letters, converted to int, only to the digital stage
Such as: var a= ' 200abc ';
var z = parseint (a);
z=200 parsefloat
Case with conversion to false
0,0.0, ', ' 0 ', null,new Array (), undefined,nan,false,function () {}
Eight. operators
Main content: arithmetic \ assignment \ comparison \ logical \ bit \ other \ string Connection (+)
Strings are concatenated in Php.
In JavaScript string connection with +
As 100+ ' 200 ' equals the result is 10200
100+200 equals the result is 300
100+200+ ' 300 ' turns out to be 300300.
' 10 ' + (2+1); The result is 103 in Parentheses.
NINE. Process Control
If () {}
else if () {} in JavaScript there is a space between else if
Switch () detection value is equal to perform
10. Cyclic Structure
1.for
2.while
3.do...while
4.break
5.continue
This article is from the "bitter php" blog, please be sure to keep this source http://haibobo.blog.51cto.com/4799843/1941971
JavaScript Learning Summary First day