JavaScript overview, javascript Overview

Source: Internet
Author: User
Tags string to number

JavaScript overview, javascript Overview
1 JavaScript 1.1 JavaScript is a scripting language
The scripting language is not used independently and must be embedded in other languages for combination.
1.2 JavaScript is parsed and executed by the browser.
1.3 JavaScript can control the logic operations of front-end pages
For example, you can control css styles.
You can verify a single table.
Dynamic Control of HTML elements
1.4 features of JavaScript
Interactivity
Security
Cross-platform
2. JavaScript composition 2.1 ECMAScript describes JavaScript syntax and basic objects
2.2 DOM Document Object: Methods and interfaces for processing webpage content
2.3 methods and interfaces for interaction between the BOM browser object type and the browser
3. Relationship between JavaScript and java

There is no relationship between the two, but the syntax is similar.


Difference between JavaScrip and java


3.1 JavaScrip is a scripting language, and java is a programming language.


3.2 JavaScrip is a weak type language, and java is a strong type language.


3.3 expose Crip is executed by the browser, and java is executed by the JVM.


3.4 objective Crip is object-based and java is object-oriented

 
4. JavaScrip and HTML combination method 4.1 internal use (Attribute combination method)
4.2 External Use
<Script type = "text/javascript" src = "file path name"> </script>
5. syntax and usage of comment Crip 5.1 comment a single line comment //
Multi-line comment /**/
5.2 variable 5.2.1 variable format var variable name = variable value in variable 5.2.1 variable Crip;
5.2.2 variable type: the variable Crip is case-sensitive.
Boolean
Number integer decimal and NaN
The placeholder of the null object, indicating that the reference type is not used in
The typeof operator returns the Object for a null value.
An error
Typeof () is used to determine the result of a variable value as the original data type.
The variable declared by undefined is not assigned a value. The system will assign an undefined value by default.
Undefined is derived from null. undefined = null // true
5.2.2.2 there is no class in the reference data type JavaScript. We can understand it as an object.
Parent class of all objects of an Object
Instanceof is used to determine the object type.

Var obj = new Object ('A'); alert (obj); // aavar obj = new Boolean (10); alert (obj ); // truevar obj1 = new Boolean ("22"); alert (obj1); // truevar obj2 = new Boolean (true); alert (obj2 ); // truevar obj3 = new Boolean (false); alert (obj3); // falsevar obj4 = new Boolean (null); alert (obj4 ); // falsevar str = 'abc'; alert (str instanceof String); // falsevar str1 = new String ('abc'); alert (str1 instanceof String ); // truevar str2 = new String ('abc'); alert (str2 instanceof Array); // falsevar str3 = new String ('abc'); alert (str3 instanceof Object ); // truevar num = undefined; alert (num); // undefinedalert (typeof (num); // undrfinedalert (typeof (num. toString (); // do not execute



5.2.2.3 type conversion 5.2.2.3.1 convert to string
Var flag = true; alert (flag); // truealert (typeof (flag); // booleanalert (typeof (flag. toString (); // stringvar num = 5; alert (num); // 5 alert (typeof (num); // numberalert (typeof (num. toString (); // stringvar num = null; alert (num); // nullalert (typeof (num); // Objectalert (typeof (num. toString (); // do not execute


5.2.2.3.2 convert to a number
                                        var str = 'abc';alert(typeof(str));//stringalert(parseInt(str));//Nanalert(typeof(str));//stringvar str = true;alert(typeof(str));//booleanalert(parseInt(str));//Nanalert(typeof(str));//booleanvar str = null;alert(typeof(str));//Objectalert(parseInt(str));//NaNalert(typeof(str));//Objectvar str = '454a55';alert(typeof(str));//stringalert(parseInt(str));//454alert(typeof(str));//string



Note:
ParseInt () converts other types to Integers and directly ignores decimals.
ParseFloat () converts other types to decimal places
If a string can be converted to a number, it is converted to a number,
If any illegal character exists, all things after the illegal character are ignored.
If the first character is invalid, it is directly converted to NaN.
Convert boolean to NaN directly
Convert null to NaN
Undefiend to NaN
5.2.2.3.3 forced type conversionBoolean (value)-converts a given value to the Boolean type;
Number (value)-converts a given value to a Number (which can be an integer or floating point Number );
String (value)-converts a given value to a String;

Note:
Boolean

String is true if it has a string value.
If it is a null string, it is false.

Number: true if the number is not 0
If it is 0 or NaN, it is false.

Nullfalse

Undefined false
5.2.3 Arithmetic Operators + symbols
Arithmetic Operations plus
String connection conversion character
Number conversion character (other types to number ):
String to number: Convert the value to the number type. If the value is not a legal number, convert it to NaN.
Example: var str = + "11 ";
Var str = 'a ';
Boolean to number: true to 1, false to 0-in addition to the operation, can be used as a conversion character
Convert null to number: Convert to 0
Undefined to number: Convert to NaN

Alert (typeof (str); // string
Alert (str); //
Str = + '11 ';
Alert (typeof (str); // number
Alert (str); // 11

When an arithmetic operator is used, it is converted to the numeric direction. If it is not a numeric type, it is not converted.

-Symbol
Subtraction of arithmetic operations
Conversion character
Number conversion character (conversion from other types to number)

5.2.4 value assignment operator = value assignment
+ = Add the original value first and assign a value (if the original value is not an operational number, it is automatically converted to the corresponding number)
-= Original values first subtract and then assign values (if the original value is not an operational number, it is automatically converted to the corresponding number)


5.2.5 comparison operator = comparison value
=== Comparison value and type


! = Comparison value
! = Compare value or compare type. The difference is different.
5.2.6 logical operators & logical and
| Logical or
! Non


If the preceding logical operators are used, the values of the boolean type are used. If the values are not of the boolean type, the values are converted.
Number to boolean: 0 or NaN to false, others to true
String to boolean: "" is false, others are true
Convert null to boolean: Convert to false
Undefined to boolean: Convert to false
Convert object to boolean: Convert to true
5.2.7 conditional operator var = (expression )? Value1: value2
5.3 process control statement if switch for while
6. Object 6.1 Number:
Var mun1 = 10; -- pseudo object alert (typeof (num1); // number
Var num2 = new Number (10); alert (typeof (num2); // Object
Var num3 = Number (10); alert (typeof (num3); // number
Attribute
MAX_VALUE; alert (Number. MAX_VALUE );

MIN_VALUE; alert (Number. MIN. VALUE );
NaN; you can use isNaN () to determine whether a value is a number.
Judgment
6.2 creation method of Boolean object:
Var flag1 = true;
Var flag2 = new Boolean (true );
Var flag3 = Boolean (true );
Alert (flag1); // true
Alert (flag2); // true
Alert (flag3); // true
6.3 method for creating a String object:
Attribute length
CharAt (5 );
Concat (str1 ,..);
IndexOf ();
Replace (srt1, str2 );
Split ("");
6.4 array var arr = [, 3];
Var arr = new Array ();
Var arr = new Arry (4); the default array length is 4
Var arr = new Array (); Array element is

Attribute length
Common Methods
Concat (,) concatenates two or more arrays and returns the connected results. This has no effect on the called array.
Join ()
Shift () deletes and returns the first element of the array. If the array is empty, the SHIFT () method does not perform any operations and returns the undefien
Pop () deletes and returns the last element of the array. If the array is empty, pop () does not change the array and undefiend is returned.
Push () adds one or more elements to the end of the array and returns the length of the new array.
Unshift () adds one or more elements to the array switch and returns the length of the new array.
Reverse () Physical flip of array elements, operations on the array
Sorting by sort () will be sorted by character code table by default, which has great defects, so it is best to implement the instance
Function sortNumber (a, B) {return a-B}

Differences between arrays in javascript and java
The length of the array is variable.
Array elements can be of any type

6.5 Date Method
Var date = new Date (); the date object is created, and the current system value is used as the initial value.
Var date = new Date (millisecond value) will create a date object
Method
ToLocaleString () returns gerDay () getMath () getfullYear () getTime () settime () parse () of a day in a month to the date format getDate () var date = new Date (); alert ("date" + date); alert ("date tolocalestring" + date. toLocaleString (); alert ("date gedate" + date. getDate (); alert ("date getDay" + date. getDay (); alert ("date getMonth" + date. getMonth (); alert ("date getFullyear" + date. getFullYear (); alert ("date gettime" + date. getTime (); calculates the number of days for a specific time difference var time1 = Date. parse ("2015/7/8"); var time2 = Date. parse (""); var long = time2-time1; alert (long/1000/60/60/24 );



6.6 Math object Method
Random ();
Round ();
Ceil ()
Floor ()

6.7 RegExp object 7 Global function 7.1 eval can use strings as JavaScript code for execution
Var str = "alert ('hello ')";
Eval (str );
7.2 isNaN () determines whether it is NaN. If the parameter is NaN, true is returned. Otherwise, false is returned.

7.3 URL
EncodeURL () Encoding
DecodeURL () decoding
EncodeURIComponent () URI encoding is applicable to passing parameters.
DecodeURIComponent () URI Decoding
Var str = "http://www.itcast.cn/a.html? Dfd = James & dfd = 123abc ";

Var tem = encodeURI (str );
Alert ("tem" + tem );
Alert (decodeURI (tem ));

7.4 URL URI
7.4.1 a URL is a uniform resource locator. The URL is a specific URI.
URI is a unified resource identifier.
 
The URL is absolute, and the resource changes the location URL
 
For example, the http://www.baidu.com is a URL, not a URI
For example, the http://www.baidu.com/a.html is either a URL or a URI

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.