Javas cript knowledge and books to get started
To enter the IT industry, to receive high salaries, this is not easy, the first need to master the relevant professional knowledge, and can pass the appropriate assessment. For many people who want to work in the relevant industry, the best way is to learn some basic knowledge and operational content, so as to be able to lay a certain foundation.
Most people think learning Javas cript is an easy thing, in fact, there is no mistake, JS is indeed an easy-to-learn language. This leads to a lot of people will use Javas cript, but very few people can use the very proficient reason, because they look at the size of JS this language foundation and intrinsic, the foundation, whenever is an important existence, the most direct is in your interview, If even JS data type can not answer it is too much. The workshop of this course is very good, the combination of theory and practice, so that students can skillfully master the relevant technology. Next, let's summarize the foundation of Javas Cript.
First, the grammar
Everything in Javas cript (variables, function names, and operators) is case-sensitive.
Identifier: Refers to the name of the variable, function, property, the identifier is required as follows
1 The first character must be a letter, an underscore (_), or a dollar sign ($)
2 other characters can be letters, underscores, dollar signs, or numbers
3 cannot use keywords, reserved words, true, false, NULL as identifiers
Comments
Single-line Comment
/*
*
* Multi-line Comment
*
*/
Strict mode
Strict mode is ES5 introduced, strict mode defines a different parsing and execution mode, in strict mode, some unsafe operation will run out of error
To enable strict mode throughout the script, you can add the following code at the top of the
"Use Strict"
You can also specify that the function executes in strict mode
function dosomething () {
"Use Strict"
// ....
}
Ii. variables and data types
Variable
1, the variable in escms cript is loosely typed, that is, Javas Cript makes the weakly typed language, in other words, the variable in JS is just a saved worthy placeholder, you can save any type of value.
2. Define variables with var operator.
3. A variable defined with the var operator becomes a local variable in the scope that defines the variable.
4. You can define global variables (not recommended) by omitting Var in function scope (block scope).
Data type
1, JS has 5 of the basic data types and 1 of complex data types they are
Undefined, Null, Boolean, number, string, and Object
2. The typeof operator is used to detect the data type of a variable, and using the TypeOf operator on a value returns a string that indicates the worthwhile type:
"Undefined"--if this value is undefined
"Boolean"--if this value is a Boolean value
"String"--if this value is a string
"Number"--if the value is numeric
"Object"--if this value is an object or null
"Function"--if this value is a function
3, JS 6 data type and use typeof to determine the data type does not correspond, the difference is that the use of typeof to get the type label is not "null", but more a "function", the others are the same, Also note that null is returned "object" when typeof is used, and the typeof operator gets a string.
Third, the statement
If statement
Grammar:
if (condition) {
}else if (condition) {
}else{
}
Explain:
Where the condition can be an arbitrary expression, and the result of the evaluation of the expression does not have to be a Boolean value, ES automatically calls the Boolean () conversion function to convert the result of the expression into a Boolean value.
While statement
Grammar:
while (condition) {
Something ...
}
Explain:
Where the condition is the same as the condition in the IF statement, the while statement is a pre-test loop statement that evaluates the conditional expression before executing the loop body, so the loop body may never execute.
Do-while statements
Grammar:
do{
Something ...
}while (condition)
Explain:
Where the condition is the same as the condition in the IF statement, the Do-while statement is a post-test loop statement, that is, the code in the loop body is executed at least once before the conditional expression is evaluated. The interesting notation is (while is the first to ask and then beat, Do-while is to beat up and then ask).
For statement
Grammar:
For (initialize code, condition, code to execute after loop body execution) {
Something ...
}
Explain:
The For statement is also a pre-test loop statement, so the loop body may never be executed, and the difference between a for statement and a while statement is the ability to initialize a variable and define the code to execute after the loop before executing the loop.
for-in statements
Grammar:
For (property in expression) {
Something ...
}
Explain:
The for-in statement is a precise iterative statement used to enumerate the properties of an object, and it is important to note that the order of the property names output by the For-in statement is not measurable, depending on the browser.
Switch statement
Grammar:
switch (expression) {
Case Value:
Statement
Break
Case Value:
Statement
Break
Case Value:
Statement
Break
Default:
Statement
}
Explain:
The switch statement is the closest process Control statement to the IF statement, and the switch statement in Javas Cript has its own characteristics, first: You can use any data type in the switch statement, followed by: The value of each case (that is, value), not just the constant, It can also be a variable or even an expression.
Iv. functions
Functions in Javas cript use the function keyword to declare
function (arg0, arg1, arg2, ..., argn) {
Statements
}
Understanding Parameters
The parameters in the Javas cript are characterized by:
Don't mind if you pass a few parameters, even if you define a function to receive a few parameters, it will not error.
It doesn't matter what data type you pass on the parameter.
This is because the parameters inside the Javas cript function are represented by a class array object, so the function is always receiving an array object of this class, rather than having any concerns about what arguments are inside the object, which can be accessed in the body of the object using the arguments object. You can use the syntax of square brackets such as: arguments[0], arguments[1], etc., this fact illustrates an important feature:
Naming parameters is not required, it just provides convenience.
The length property of the arguments learns how many arguments are passed to the function:
function Howmanyargs () {
alert (arguments.length);
}
Howmanyargs ("string", 1); 2
Howmanyargs (); 0
Howmanyargs (1); 1
A bit more interesting about arguments is that its value is always synchronized with the corresponding formal parameter, that is, modifying the value of Arguments[0] will change the value of the corresponding named parameter accordingly. But this is not to say that they are accessing the same memory space, they have separate storage space, but the value will be synchronized, in addition, if the value is passed a parameter, modify the value of arguments[1] will not change the value of the corresponding named parameter, this should be, The length of the arguments.length is determined by the number of arguments passed, not the number of named parameters, which is emphasized once again, the naming parameter is just a convenience and has no other effect.
No overloads
Because the function in Javas Cript does not have the feature of a function signature, there is no overload, but you can simulate overloading by checking the type and number of parameters passed in to the function to react differently.
Here are some books for you to recommend
Introductory Book of choice: "Javas cript DOM Programming Art"
The content of the book is simple, easy to learn, quick to get started, rigorous programming thinking. A good introductory book will have a profound effect on your future programming. This book does not disappoint this historical mission.
Book of basic Study: The authoritative guide of Javas Cript
"Javas cript DOM Programming Art" is just an introduction to programming ideas and simple program syntax as well as the basic methods of DOM. The Javas cript authoritative guide describes the various functions and features of Javas cript in detail. As for the reference (Javas cript core Reference, client Javas cript Reference, DOM Reference), which is about 500 pages in the back, you can temporarily leave it.
Advanced books: "Javas cript high-level program design"
Emphasis on the concept of OPP, the content of the focus on practical, you can learn more and more detailed knowledge, and focus on the resolution of browser differences. But if you want to read must have a certain Javas Cript Foundation (or read the first two), otherwise it will bring frustration, to combat the enthusiasm of learning.
Expand Learning: "Ajax Combat"
More comprehensive and in-depth introduction of Ajax knowledge, in which the idea of Ajax development and Ajax development design patterns are still worth learning. It is better to read this book on the basis of "Javas Cript Advanced Programming", which can help to understand the contents of the book well. Of course, for a friend without background language Foundation, reading is still a certain obstacle.
Javas Cript level to a certain extent, the book see no more can not get the last technology upgrade, at that time need to practice, write their own code, deep into the development of exercise, the theory of reality, will enhance the value.
Javas cript knowledge and books to get started