JavaScript Knowledge points Summary

Source: Internet
Author: User
Tags function definition

JavaScript Learning Summary
1.JavaScript is a programming language for Web and HTML.
2.JavaScript code must be placed between <script></script> tags, javascript is now the HTML default scripting language, so in <script> There is no need to declare the scripting language as JavaScript in the label, i.e. type= "Text/javascript" is not required.
3. You can add any number of scripts in HTML document, JavaScript can be placed in the 4.JavaScript can be placed in a separate JS file, need to use when the page is introduced. External JS code may not contain <script> tags.
5.JavaScript does not have any built-in print and display functions, there are four ways to output information:
A) Window.alert () write the information to the popup box.
b) document.write () writes the information to the HTML output, noting that executing document.write () after the HTML document is fully loaded will delete all HTML elements of the page.
c) innerHTML writes the information to an HTML element.
d) console.log () output the information to the browser console.
The 6.JavaScript syntax defines two types of values: Fixed values are also called literals, numbers are expressed in decimal notation or not in decimal notation, and the string is a literal, written in double or single quotation marks. such as ' LCW ', 4, variable values are also called variables, used to store values, JavaScript uses the "var" keyword to declare variables, using a "=" to assign them. such as Var x; x = 6.
7.JavaScript Use mathematical operators +-*/calculate values.
8.JavaScript in//after and in the/**/content is the comment content, when the code execution is ignored, it is recommended to use//comments,/**/can write some formal documentation.
The 9.JavaScript identifier is used to name the variable, the first character of the variable name must be a letter, underscore, or dollar sign ($), other characters can be letters, numbers, underscores, dollar signs, numbers are not allowed as the first character of a variable name, So JavaScript can easily distinguish between numbers and identifiers, in JavaScript, the case will be judged, such as LastName and LastName are different variables, VAR will not be interpreted as the keyword VAR, "-" is not a character in the identifier , which is used as a minus sign in JavaScript.
10. At the end of each sentence the semicolon is not necessarily there, but it is strongly recommended to add. In order to increase readability, you can add some spaces to the code, such as adding a space before and after the equals sign in an assignment statement, and the code will look more beautiful, usually with spaces on either side of "+", "-", "*", "/", "=".
11. In the actual code, if a row occupies too long, you can wrap the line at the equals sign.
12. It is recommended that all variables be declared at the beginning of the code.
13. In JavaScript, if a variable is declared, it is not assigned a value, its default value is: undefined.
14.+ is used in string operations, which are equivalent to connectors.
15. At the time of operation, note that the operator has precedence.
16. When you add a number and a string, the number is treated as a string.
17.JavaScript has a dynamic type attribute, when a variable is declared, assigned a value, its type is the type of the value, and if it is assigned a value of another type, the type of the change will change accordingly.
18. When defining a string, single and double quotation marks can be nested with each other, paying attention to the question of quotation marks pairing.
Array subscripts in 19.JavaScript start with 0, in JavaScript arrays are objects, variables with no assigned value typeof return value is undefined, note var v = "", V's typeof return value is string, its value is "", Note The return value of the null typeof is object.
20. The rules defining the function name are the same as the rules that define the identifiers, inside the function.
21.return will end the execution of the code.
Objects in 22.JavaScript are containers for properties and methods.
23. To define an object, there are two ways to access the property: 1. Object name, property name, 2. Object name ["Property name]". Invokes a method object name. The method name (), if written as the object name. Method name, returns the definition of the function.
24. Try not to declare a variable with the new keyword, which complicates the code and slows execution.
25. Variables defined inside the function are local variables that can only be accessed inside the function, that is, the scope of the variable, the arguments passed in when the function is called as local variables within the function, and the variable names within the functions can be the same.
26. Local variables within the function are created at the end of the function when the function is executed.
27. Variables defined outside the function are global variables, and global variables can be accessed from anywhere.
28. If you assign to a variable that is not declared, the variable will automatically become a global variable and try not to define a global variable.
29. Global variables or functions can override window variables and functions, and vice versa.
The lifetime of a variable in 30.JavaScript begins when it is declared, the local variable is deleted after the function is executed, the global variable is deleted when the user closes the page, and all global variables in the HTML are the Window object.
31.\ can convert characters with special meanings into Word such as var a = "Qwer\" qw\ "er";
32.JavaScript considers some primitive types of data like strings as objects, and they also have properties and methods.
The storage of numbers in 33.JavaScript is a double-precision floating-point type, occupies 64-bit size, 0-51 is a numeric value, 52-62 represents an exponent, and 63-bit indicates positive or negative. When representing integers, more than 15 digits are inaccurate, and do not take 0 as the first digit.
34. The default JavaScript display number is 10 binary. can be converted to 8 via ToString (8), or other binary.
35.infinity/-infinity, Integer In addition to 0 is Infinity, negative number except 0 is the type of-infinity,infinity is number.
The result of 36.NaN, not a number,100/"Apple", is that Nan,100/"10" results in 10.
Comments in 37.JavaScript are recommended for use with//,/**/in formal instructions.
38. In practical programming it is best to declare all variables at the beginning of the scope of the variable.
String is a constructor in 39.JavaScript, and string is the data type.
The function name in 40.JavaScript stands for the definition of functions, and the function name () represents function execution.
41.JavaScript when setting a time, if no time zone is set, JS will use the browser's time zone, when a time is obtained, if the time zone is not set, the result will be converted to the browser time zone.
42. Note When defining an array, the last element of the array is not added at the end of the ",", and the subscript index of the array in JavaScript starts at 0.
43. If the index is named when the array is defined, JavaScript will redefine the array as a standard object, so that some properties and methods of the array will return the wrong result. such as: var person = []; person["Firstone"] = "LCW"; PRESON.LENGTH,PERSON[0] The returned result and expected will not match.
The array in 44.Javascript uses a numeric subscript index, and the object uses a named index. Arrays is a special object that uses a numeric subscript index.
45. All JavaScript objects have the valueof () and ToString () methods.
46. In JavaScript, the values of all primitive types are used by JavaScript to treat them as objects when executing the Get properties and executing methods.
47. Note the difference between "= = =" and "= =" in JavaScript, and the difference between "! =" and "!==".
The numbers in 48.JavaScript are converted to 32-bit representations when they are operating.
In the switch statement in 49.JavaScript if default is not the last story, "break;" End.
Variables in 50.JavaScript can be converted to another new variable and another data type, JavaScript itself converts the variable type, or it can use the function transformation provided by JavaScript.
51.JavaScript automatically calls the ToString () method of the variable when we try to output a variable or object. \
52. In JavaScript, try and catch are always paired, and JavaScript stops normally when an error occurs, generating an error message.
The Throw keyword in 53.JavaScript can throw the new Error (""); or throw "error";
The 54.JavaScript has the lift imagination that JavaScript will move all the declarations to the front of the scope of the variable, so that the code can use variables that have not been declared while the code is executing, but if the variable is initialized at the time of declaration, it will not be "lifted". The lift is simply a variable declaration and does not include variable assignment.
55.JavaScript uses the ' use strict ' declaration to interpret execution code using strict mode, and strict schema declarations have scope problems, that is, the extent of strict mode action, and this declaration is only at the beginning of the code or the beginning of a function.
56. It is best to initialize the variable when it is declared, which avoids the undefined value.
57. Try not to declare the object with the new keyword, directly back to the variable assignment.
58. It is a good idea to initialize each parameter within the function to assign a value.
59. When declaring a switch statement, it is best to add the default at the end.
60. Avoid using eval () as much as possible;
61. In the development to note that JS loading will delay page loading, if you need to download the JS file from the remote server, according to the HTTP definition can not download multiple components in parallel.
Data types in 62.JavaScript, 1. Simple data type: Undefined, null, Boolean, number,string;2. Complex data type: object;
The value type returned by typeof in 63.JavaScript: Undefined, null, Boolean, number,string,object,function.
64. In JavaScript, the object is the king, and if we can understand the object, we understand JavaScript.
65. A JavaScript object is a named collection of values, from other places such as performance, it is best to use literal declaration objects.
66. Each JavaScript object has a prototype, and the prototype is an object, and all JavaScript objects inherit methods and properties from the prototype.
67. The Declaration of a function is "lifted", so execution can be called before the function declaration.
The function definition in 68.JavaScript does not specify the data type of the parameter, JavaScript does not check the data type of the passed arguments, and JavaScript does not examine the number of incoming parameters, so when a function is called, the arguments passed to it are not equal to the number of arguments to the function declaration. Will not have an effect, you can use the arguments object to get the value if the passed parameter exceeds the number passed in the function declaration.
The "This" keyword is the object that owns the current code when the project is executed, and when used in a function, refers to the object that owns the method.
70. Variable creation without the "var" keyword, the variable will be a global variable, even if the variable is defined in the function.
71. All functions in JavaScript can access the scope in which it belongs.
A closure in 72.JavaScript is a function that can still access the parent scope after the parent function has been closed.

JavaScript Knowledge points Summary

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.