JavaScript-a summary of knowledge points

Source: Internet
Author: User
Tags string indexof

JS syntax

1. JavaScript data type

JavaScript has a dynamic type. This means that the same variables can be used for different types: strings, Numbers, Booleans, objects, arrays, undefined, and null

Object:
var person={firstname: "John", LastName : "Doe", id : 5566};
Object properties are addressed in two ways:
name = Person.lastname;
Name = person["LastName"];
Undefinied: Indicates that the variable does not have a value of NULL: Indicates that the value of this variable is null

 

Declaring variable types: variable types can be declared with the new keyword var carname = new String;var x= new Number;var y= new Boolean;var cars= new array;var person = n EW Object;

* JavaScript variables are objects. When you declare a variable, a new object is created

2. JavaScript is case sensitive.

3. A command issued to the browser by a JavaScript statement. The purpose of the statement is to tell the browser what to do. JavaScript is a scripting language. The browser executes the script code row by line while reading the code

4. JavaScript uses semicolons to separate statement semicolons;

5. JavaScript wraps a line of code in a text string using a backslash

document.write ("Hello World!");

6. Note: single-line comments begin with//start multiple lines of comments starting with/*, ending with */

7. Variables: Use var keyword to declare variables

var carname; After a variable declaration, the variable is empty (it has no value) and the value is undefined
var carname= "Volvo"; declaring and assigning values

A statement can declare multiple variables at the same time

var lastname= "Doe", age=30, job= "Carpenter"; The effect is equal to
var lastname= "Doe"
var age=30
var job= "Carpenter";

Local variables: Variables declared inside a function (using VAR) are local variables that can only be accessed inside the function.

Global variables: Variables that are not declared within any function are global variables, and all scripts and functions on a Web page can access it

Life cycle: The lifetime of JavaScript variables begins at the time they are declared.

Local variables are deleted after the function is run.

Global variables are deleted after the page is closed.

* If you assign a value to a variable that is declared:

Carname= "Volvo";//a global variable carname is declared, even if it is executed inside the function.

8. JavaScript objects: JavaScript objects are containers for properties and methods

Object methods
var person = {name: ' Tom ', Age:20,behavior:function () {Console.log (this.name)},
Behavior2:thismethod//Another form};

function Thismethod () {
Console.log (' name ');
}

  

Access Object method function Testgetobjectmethod () {person.behavior ();
Person.behavior2 ();
}

9. JavaScript scope: A collection that can be understood as an accessible variable

In HTML, a global variable is a Window object: All data variables belong to the Window object

Window.myname = ' all can get '; This variable can get everywhere

* Global variables, or functions, can overwrite variables or functions of the Window object. local variables, including window objects, can override global variables and functions.

Ten. JavaScript Common events:

HTML events are things that happen on HTML elements.

HTML events can be browser behavior or user behavior.

Common events: OnClick, onchange, onmouseover, Onmuseout, onkeydown, onload

A. JavaScript string object;

* A backslash is an escape character . The escape character converts a special character to a string character eg: \ \ \ \ \ r \ n

String property constructor Returns the function that creates a string property length returns the lengths of a string prototype allows you to add properties and methods to an object

  

String method
CharAt () returns the character of the specified index position charcodeat () returns the Unicode value of the specified index position character concat () joins two or more strings, returns the concatenated string fromCharCode () the Unicode Converts the string indexof () back to the string to retrieve the first occurrence of the specified character in the position LastIndexOf () returns a string that retrieves the last occurrence of the specified character localecompare () compares two strings in a local-specific order to match () Finds a match for one or more regular expressions replace () replaces a substring matched with a regular expression search () retrieves a value that matches a regular expression slice () extracts a fragment of a string and returns the extracted part of Split () in a new string Splits a string into a substring array substr () extracts a specified number of characters from the starting index number in a string substring () extracts the characters between two specified index numbers in a string tolocalelowercase () converts a string to lowercase based on the locale of the host. Only several languages (such as Turkish) have a local case-specific mapping tolocaleuppercase () converts a string to uppercase based on the host's locale, and only several languages (such as Turkish) have a local-specific case map tolowercase () Converts a string to lowercase tostring () returns the String object value toUpperCase () converts the string to uppercase trim () removes the string from the end of the white space valueof () returns the original value of a string object

JavaScript operators:

JavaScript-a summary of knowledge points

Related Article

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.