mdn--javascript--Introduction--The first chapter--Summary of knowledge points

Source: Internet
Author: User

1. What is js:

JavaScript is a programming language that allows you to implement complex things in a Web page

Example:

var para = document.queryselector (' P ');

Para.addeventlistener (' click ', UpdateName);

function UpdateName () {

var name = prompt (' Enter a new name ');

Para.textcontent = ' Player 1: ' + name;

}

JS APIs:

1 Browser APIs:

DOM, geolocation API,canvas and WebGL(Create 2d3d image), Audio vedio API

2 third-party APIs:

(default is not installed on the browser) Twitter API Google Maps API

Interpreting code vs Compiled code

in the programming environment, you may have heard of these two terms explain [Interpreted] and Compiling [Compiled] . JavaScript is an interpreted language --the code runs from top to bottom, and the results of the run are returned immediately. You don't have to convert it to another form before the browser runs the code.

on the other hand, a compiled language needs to be converted to another form before it is run. For example , C + + will be compiled into assembly language, and then run by the computer.

inline javascript code in HTML: However, do not: This is a JavaScript to pollute your HTML Bad practice, and it's not efficient-you'll need to include onclick= "createparagraph ()" On every button you want JavaScript to apply to. property.

2. JS First Step (problem solving steps)

1. Thinking algorithm

2. Create a problem solving process all variables (including data, DOM elements to manipulate )

3. Create the required functions (functional modularity)

4. invoke the function x.addeventlistener (' click ', fn) through the practice listener;

in JS , everything is an object. Objects are collections of related features that are stored in a single grouping. Objects have properties and methods, you can create a variable to point to an object, so that you can access the properties and methods of the object through a variable

3. What's wrong with the place? (Find / fix bugs)

Error type:

1. syntax error ... Code spelling error or something, can be repaired by error message

2. Logic Error ... The syntax is correct, but does not reach the desired effect, no error message, more difficult to find

Common syntax errors

TypeError:guesssubmit.addeventlistener is not a function: Possible function name error

TypeError:lowOrHi is null: May not get to Dom, variable does not point to object

syntaxerror:missing; Before statement: missing after declaration '; '

syntaxerror:missing) after argument list: missing after parameter )

Syntax error reference Documentation:

Https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors

Logic Error Checking:

Console.log () or something.

4. variables

A variable is a container for storing values that can be changed

Variables are not the values themselves, they are just a container for storing values. You can think of variables as a box of paper used to load things.

Declaring: Creating a variable

The declaration is uninitialized and the value is undefined

Undeclared use of variable will cause an error

Variable name

Numeric letter underlined $,

Don't start with numbers

It's best not to start with, and to confuse some constructs.

Hump Type setresetbtn

Case sensitive

It's better to have semantics

variable type / data type

Number

String

Boolean

Array

Object

Loose Typing

Js is loosely typed language / weakly typed language

Declaration does not add type

Data types that can be stored

5. Numeric Operators

In the comparison operator

= = = Congruent, requires the same data type

!== strictly unequal,5!==2+3:false ' 5 '!==2+3:true equals = = = Take counter

It is recommended to use = = = and !== instead of = = and ! =, resulting in fewer errors

6. String

Single and double quotes are the same, but it's best to stick to habit

escaped:\ '

Type conversions

Turn into characters:

var a=36+ ';

X.tostring ();

Turn into numbers:

number (value)

7. String Common methods

because everything is an object in JS.

so string is also an object

Var a= ' string ';

Property

A.length

A[0]

Method

A.indexof (' sub-string ');

Returns the first- digit index of the first occurrence of a substring,1 for non-existent

A.slice (0,3);

returns a string on the 0,1,2 bit

A.slice (2);

returns the remaining string starting at 2 bits

A.tolowercase ()

A.touppercase ()

A.replace (' m ', ' n ');

replace m with n

8. Array

var arr=[1,2,3,4,5,6, ' string ', [0,1,2]];

visit:arr[0] arr[7,0]

Properties :

Arr.length

Method:

Arr=str.split ('. ')

to . The delimiter is Str divided into arr

Str=arr.join ('. ')

to . for the connector arr Lian Cheng Str

Arr.tostring () is equivalent to connecting arr.join with commas (', ')

adding elements

Arr.push (' A ', ' B ', ' C ');

add an element to the end , return a value to an array new length

Arr.unshift ()

add element to beginning, return value to new length

Delete Element

Arr.pop ()

Removes the last element, the return value is the deleted element

Arr.shift ()

Delete the front-most

Typed arrays: Class array objects

mdn--javascript--Introduction--The first chapter--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.