I am a beginner, but I can learn a little bit of knowledge! The following is according to Hanshunping teacher's "easy to get the Web design Html+css+javascript-javascrip part" organized.
Why do you learn JavaScript?
JavaScript is the cornerstone of Web page dynamic performance, plays an important role in web development, and is widely used in various fields:
- Web Games
- Map Search (Google,baidu)
- Stock Market Information Query
- Web Chat
In web development, JS is an essential technology! At the same time JS is the basis of AJAX/JQUERY/EXTJS and other frameworks.
Introduction to JavaScript--Basic introduction
JavaScript is a scripting language widely used in client-side web development, often used to add dynamic functionality to HTML pages, such as responding to user actions.
What is a scripting language?
- scripting language between programming languages such as HTML and c,c++,java,c#
- Scripting languages are similar to programming languages, and their functions are similar to programming languages and have variables. The biggest difference from programming languages is that the syntax and rules of a programming language are stricter and more complex.
- Scripting language is an explanatory language (that is, executing directly on the source code at the time of execution), such as Python, Vbscript,javascript, and so on, which are not compiled into binary code, such as C + +, etc. ( explanation of the difference between the language/compiler language, is this a question?)
- Scripting languages generally have a corresponding scripting engine to interpret execution, and JavaScript's scripting engine is the browser.
- JS scripting language is often not used independently, it is meaningful with the use of html/jsp/php/asp/asp.net
The main purpose of JavaScript is to let the elements in the Web page be programmed to make the Web page move, and even you can write the JS version of the Tank war game. JavaScript cannot run independently, it must be embedded in other programming languages to run (html/asp/asp.net/jsp/php ...) JavaScript can only be used for B (Brower browser)/s (server server) development, which is what we often call Web development (e.g. Web development, Web applications, etc.); JavaScript is mainly for client programming, that is, JS is generally run on the client; JavaScript can also be programmed on the server side ( less ); The latest version of JavaScript is 1.8 ( at that time, but now it's not known how much ); JavaScript executes on the client (browser).
Introduction to JavaScript--History of development
JavaScript, originally called LiveScript, is an object-and event-driven, security-based scripting language developed by NETSCAPCE (Netscape) 1996, and then partnered with Sun to rename LiveScript to JavaScript.
Because of browser differences, we will see that in different browsers using JS programming, there will be differences, for example, when a control to bind the response function, the Web DOM Standard is AddEventListener (), and IE is using attachevent (), There are some methods in IE can be used, but in the FF is not used, these are our actual development to pay attention to the problem. (Because JS is interpreted by the browser, so there is a problem, different types of browsers may not be the same for JS support.) )
features of JS language
The JavaScript language is simple;
JavaScript is Object-based and event-driven (dynamic);
It can respond directly to user or customer input without having to go through a Web service program. It responds to the user in an event-driven manner. Event-driven refers to the action that occurs when an action is performed on the home page, called an "event." For example, pressing the mouse, moving a window, selecting a menu, etc. can be considered an event. When an event occurs, a corresponding event response may be caused.
JavaScript is cross-platform.
JavaScript is dependent on the browser itself, regardless of the operating environment, as long as the browser can run the computer, and support JavaScript browser can be executed correctly.
JS is a script programming language;
JS is interpreted to be performed.
JS can be programmed on the client, or the server can be programmed (less).
JavaScript and JScript comparison
- JScript was developed by Microsoft, while JavaScript was developed by Netscape and Sun.
- When Netscape developed the LiveScript (JavaScript predecessor), Microsoft realized that the scripting language would be very hot, so found Netscape said it wanted to co-develop LiveScript, but Netscape eventually chose to work with Microsoft's rival Sun to develop LiveScript, and renamed to JavaScript.
- Microsoft angrily, the development of the scripting language for IE, and named JScript, in the two scripting languages at that time, the syntax is very different, to the programmers of the time to bring a lot of trouble, and then the Internet, the Unified Standard (ECMASCRIPT) So now the syntax of these two scripting languages can say that more than 90% are the same.
- To some extent, you can assume that JScript and JavaScript are the same.
- It's no surprise to search the JavaScript help manual on the web and open it up to a JScript help manual.
JS's first instance, Hello world
<! DOCTYPE html> Window.alert ("HELLO1 world!!!" ); </script>
Attention:
- JS location can be arbitrary.
- JS must use <script type= "Text/javascript" >js code </script>, if not used script package, the browser will treat it as normal text.
- Multiple pairs of <script> fragments can appear in an HTML file (jsp/php/asp, etc.). browsers are executed sequentially. (not illustrated here)
preliminary understanding of JS variable definition and use
Look at the following example:
<! DOCTYPE html>//JS in the definition of variables (in JS, the variable is represented by Var, regardless of the actual type) num1 = 456; = the; // Num2 = result = Num1 + num2; Window.alert ("The result is =" +result); // Alert function </script></body>
Note: Thedefinition of the variable in JS (in JS, the variable is represented by Var, regardless of the actual type).
Why does JS need variables
Regardless of the language in which the program is written, the variables are the basic constituent units of their program. JS is the language of a weak data type, and when defining a variable, you do not need to indicate the type of the variable (as determined by the JS engine). For example:
var name= "Shunping"; // name is a string var kk=2; // KK is a number var yy; // yy is undefined
If name=234, then name automatically becomes number.
Do not declare variables can also be used directly:
x=345; // can also
How is the type of JS variable determined?
- JS is a weak data type (for strong data types) language, that is, when defining variables, the use of a uniform var expression can, or even do not write.
- The variable data type in JS is determined by the JS engine.
JS Basic Syntax
The identifier in JavaScript.
Identifiers are symbols defined in JavaScript, such as: variable names, function names, array names, and so on. Identifiers can consist of any order of uppercase and lowercase letters, numbers, underscores (_), and dollar signs ($), but identifiers cannot start with numbers and cannot be keywords/reserved words in JavaScript .
Examples of valid identifiers: Indentifier, username, user_name, _username, $username.
Examples of illegal identifiers: int, 98.3, Hello world.
JavaScript is strictly case-sensitive computer and computer are two completely different symbols.
The format of the JavaScript program code: Each function executes a statement with a semicolon (the end of the;), separated by a space, tab, line break, or curly brace, parenthesis, and so on. Statement blocks are represented using {}.
Comments for JavaScript programs:////(multiline comments) can be nested "//" (Single-line comment) comments, but not nested "/*...*/".
JavaScript Basic data Type--three major types
With typeof , you can see what the variable's specific data type is. The following example:
<! DOCTYPE html> var v1 = "abc"; var v2 = 890; Window.alert ("V1 is" +typeof v1); Window.alert ("v2 is" +typeof v2); V1 = 567;//js is a dynamic language Window.alert ("V1 is" +typeof v1); </script>
Number (numeric type):
- Shaping Constants (10 binary \8 binary \16). Hexadecimal starts with 0x or 0X, for example: 0x8a; octal must be opened with 0, for example: 0123; the first digit of the decimal cannot be 0 (except for the number 0), otherwise it is treated as a 8 decimal, for example: 123.
- A constant of the real type. 12.32, 193.98, 5E7, 4e5 and so on.
Special values:NaN(not a number), Infinity (Infinity), IsNaN (), Isfinite ().
JS Basic syntax--composite data type
Composite data types: arrays, objects.
JS Basic Syntax--Special data types
JavaScript Special data types: null, undefine.
var NULL ; Window.alert (a); // Null empty value
Window.alert (a); // uncaught referenceerror (Catch reference error): A is not defined (undefined)
var A;window.alert (a); // If you do not assign a value to a, you will return a undefined
JavaScript Basics (i)