Learn JS today to do some summary, share to everyone

Source: Internet
Author: User
Tags array definition local time rounds script tag

One
The role of 1.javascript
is an object-and event-driven language that is applied to the client
Object-based : provides many objects that can be used directly, without the need to create
Event-driven : HTML makes site static effects, JavaScript dynamic effects, for example: button click
client : specifically refers to a browser

2.js
  (1) Interactivity         -Dynamic interaction of information
  (2) Security        -JS cannot access files on Local disk
  (3) cross-platform      -Java cross-platform, virtual machine
  -only can support JS browser, can run
3.javascript and Java differences (Lei Feng and Leifeng Pagoda)
  ( 1) Java is Sun, now Oracle;js is Netscape
  (2) JavaScript is Object-based, Java is object-oriented
  (3) Java is a strongly typed language, JS is a weakly typed language
  -such as in Java int i = "ten";
  -js:  var i = ten; var m = "Ten";
  (4) JavaScript can be executed only by parsing, and Java needs to be compiled into a bytecode file before executing

The composition of the 4.javascript
(1) ECMAScript---has the ECMA organization developed JS syntax, statements .....
ECMA : European Computer Association
(2) Bom-broswer object model: Browser objects Models
(3) Dom-document object Model: Document Object models

Second, JS and HTML combination mode (*******)
The first type :-Use a label <script type= "Text/javascript" > JS code; </script>
The second type :-Using the script tag, introduce an external JS file
(1) Create a JS file 1.js, write JS code
(2) Introduction: <script type= "Text/javascript" src= "1.js" ></script>
Note: * * when using the second method, do not write the JS code in the script tag, will not be executed.

c. JS primitive type and declaration variable (*******)
Define variables: Use the keyword var format: var variable name = variable Value
Five primitive types
string: var str = "ABC";
Number: The numeric type var m = 123;
Boolean:true and false var flag = true;
Null: An empty object gets a reference to the object, null indicates that the object reference is empty, and the reference to all objects is also an object
Undefined: There are two scenarios that are not defined:
1. Define a variable that has no assigned value
2. Object properties do not exist

typeof (variable name)--> get the data type of the variable


Four, JS operator (*******)
1.js does not distinguish between integers and decimals
2. The addition and subtraction of string operations
NaN--non-numeric, such as the result of a string participating in a division operation.
var str = "ABC"; Hint Nan: Indicates not a number
alert (str+1); The result of operation in Java is 4561, inside JS or 4561
alert (str-1); Subtract time, perform the operation of subtraction
3.boolean type can also be manipulated
If set to True, this value is equal to 1
If set to False, this value is equal to 0
4.== and = = = Difference
= =: The value of the comparison. A simple type conversion is also possible.
= = =: values are equal and types are equal.
5. Introduction of Knowledge
Statements that are output directly to the page (you can display the content on the page)
* document.write ("AAA");
*document.wirte ("* * Can output variables, fixed values and HTML code to the page

V. JS statement (*******)
If Judgment statement '
=: denotes assignment = =: indicates judgment
Switch Statement
Structure with Java, in JS inside the switch statement what type support all support
Loop statement for while Do-while

Six, JS Array (*******)

What is an array?
-use variable, var m = 10;
-the array definition inside Java int[] arr = {A-n-a};
Definition method (three kinds)
First : var arr = [three-way]; var arr = [1, "4", true];
second : Using the built-in object array object
var arr1 = new Array (5); Defines an array whose length is 5
Arr1[0] = "1";

Third : Use the built-in object Array
var arr2 = new Array (3,4,5); Defines an array in which the elements are 3 4 5
* There is an attribute in the array length: Gets the lengths of the array
* Arrays can hold data of different data types

function of JS (dynamic function and anonymous function) (*******)

  There are three ways to define functions (methods) in JS
  (1) To use a keyword function
     function method Name (argument list) {
     method body;
     return value is optional (according to actual needs);
&NBSP;}
(2) anonymous function
 var add = function (argument list) {
      method body and return value;
&NBSP;}
(3) dynamic function (with less, understanding)
  Use a built-in object function in JS
    var add = The new Function (parameter list, method body, and return value);

VIII. global variables and local variables (*******) for JS
Global Variables : Define a variable in the script tag, which can be used in the JS section of the page
-Used outside the method, used inside the method, and used in another script tag
Note: When you define a variable that does not use VAR, the default variable is global
Local Variables : Define a variable inside a method that can only be used inside a method
-If you call this variable outside of the method, you are prompted with an error
-SCRIPT5009: "NN" undefined
Using the browser's console (press the shortcut key F12)
Note: Local variables and global variables have the same name, preference for local variables

function overloading of the Nine and JS (*******)

No overloads in JS
Can simulate overloaded phenomena, using a JS array object
The parameters in the JS function can be considered as an array multiple functions are stored in the array and are returned or applied according to the following requirements

JS Object
one, JS string Object (* * * *)
The string object is used to manipulate text (strings).
String object property: Length of String
Method of the String object:
HTML-related methods
Big () displays the string in a large font.
Bold () to display a string with boldface
FontColor () Displays the string using the specified color.
FontSize () Displays the string using the specified dimensions.
A similar approach to Java
CharAt (subscript position) returns the character at the specified position.
INDEXOF (SUBSTRING) retrieves a string.
SUBSTRING (start subscript, end subscript) extracts the characters between two specified index numbers in a string.
substr (start subscript, intercept length) extracts the specified number of characters from the starting index number in the string.
Split (delimiter): Used to split a string into an array of strings.

Second, JS Array object (* * *)----Array Object
The Java array is immutable, and the JS array can change the length
Length: Sets or returns the number of elements in the array
Concat (): Joins two or more arrays and returns the result.
Join (): puts all the elements of the array into a string. element is delimited by the specified delimiter.
Push (): Adds one or more elements to the end of the array and returns the new length.
Pop (): Delete and return the last element of the array
Reverse (): Reverses the order of the elements in the array

Third, JS's Date object (* * * *)
The Date object is used to process dates and times.
Syntax for creating a Date object: var mydate=new date ()

toLocaleString (): Converts a Date object to a string based on the local time format.
toLocaleDateString (): Converts a date part to a string based on the local time format
GetDate (): Returns a day in one months from a Date object (1 ~ 31)
GetDay (): Returns a day of the week from a Date object (0 ~ 6)
GetMonth (): Returns the month from the Date object (0 ~ 11)
getFullYear (): Returns the year as a four-digit number from a Date object
GetTime (): Returns the number of milliseconds since January 1, 1970
Parse (): Returns the number of milliseconds from midnight January 1, 1970 to a specified date (string)

Four, JS Math Object (* * * *)
Ceil (x) rounds a number.
Floor (x) rounds down a number.
Round (x) rounding a number to the nearest integer
Pow (x, y) returns the Y power of X
Random () returns the number 0 ~ 1

Five, JS global function (* * *)
Global properties and functions are available for all built-in JavaScript objects

Eval (): Executes the JS code (if the string is a JS code, use the method to execute directly)
encodeURI (): Encode characters This method does not encode ASCII letters and numbers,
These ASCII punctuation marks are also not encoded:-_. ! ~ * ' ()

decodeURI (): Decoding characters
/*
encodeuricomponent (): Encode characters
Note the difference between the encodeURIComponent () function and the encodeURI () function, which assumes that its arguments are part of a URI (such as a protocol, hostname, path, or query string). So the encodeURIComponent () function escapes the punctuation used to separate the various parts of the URI
decodeURIComponent (): The URI encoded by the encodeURIComponent () function can be decoded.
*/

IsNaN (): Determines whether the current string is a number if it is a number, returns False if it is not a number, returns True
parseint (): type conversion

(1) There is no overload in JS.
(2) However, it is possible to simulate the overloaded effect in other ways (via the aruguments array)

Learn JS today to do some summary, share to everyone

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.