javascript introductory tutorial (a): Basic Concepts

This article recommends that people have html-based, due to excessive js content, it is proposed with the "javascript Advanced Programming" taking.

Before beginning, I briefly explain the javascript the language bar.

javascript born in 1995, is mainly used to verify the form, although the name there are java, but java and has nothing, even large differences in syntax, is said to be of only ten days out of the design, because the fire was very java , so in order to hitch a ride, the author will be named "javascript", hasty design also led this language has many defects, had been abused in the pop, led to a lot of misconceptions, so js long time where programmers have been disgusted, until later created a Google ajax, js the language began to emerge, html5 and even more so after js suddenly become one of the most popular languages.

javascript total consists of three parts, namely ECMAScript (the latest version is ECMAScript2015, short es6), DOM, BOM. ECMAScript method which provides the core language features (variables, object-oriented, closures, etc.), DOM provides access to web pages of methods and interfaces (intuitive understanding is achieved in a variety of effects on the page), BOM provide interaction with the browser and interfaces.

**

Why js file into the <body> at the bottom is important?

**
Because the document is parsed from top to bottom, it is generally put into the body js references to the bottom, rather than into the head, a problem is that beginners often encounter similar "Can not read property 'style' of undefined "so, this is because the js file on the head, the document will first execute js file, and then parse the DOM element, if the DOM manipulation in js inside, undefined error occurs, of course, this can be js file window.onload method to get rid of, but if too many js file will result in DOM has been waiting to be rendered, the page will appear blank, which is not conducive to the user experience.
(Tip: <script> tag there is also a "defer" attribute, this script will be delayed until after the entire page parsed completely executed, but delayed because of the uncertainty of the script, not necessarily executed in the order, so it is best It contains only a delay script)

Promiscuous mode and standard mode

IE browser was first introduced the concept model document, document mode generally refers to the standard mode and mixed mode, if the general did not declare the beginning of the document mode, the browser will default to promiscuous mode to render the page, this will lead to different browsers particular difference large, are now generally used standard mode declaration document type of html5 <! DOCTYPE html>, js there document.compatMode attributes, when the value CSS1Compat standard mode, when the value BackCompat promiscuous mode. Promiscuous mode and a standard mode in the development of specific differences will be explained in more detail later.

Strict Mode

As previously mentioned, js is a flawed language, it also led to the development of a lot of strange bug appears, es5 introduced the concept of strict mode, as long as the front js file plus "use strict"; this code can turn strict mode, so you can know the error code will appear in advance, ie from 10 starts is supported strict mode. As a matter of strict mode requires attention, I would suggest at the time of encounter later.

Low coupling

Although the case began to talk coupling it does not seem good, but I would like to mention. Because Beginners generally like js directly embedded in the DOM, such as <input type = "button" value = "submit" onclick = "alert (this.value)" />, such an approach is actually very friendly, is not conducive to post-maintenance, just as popular now as the separation of the front and rear end, css and js files also need to be separated from html inside, so post-maintenance and reuse is more convenient.

O (∩_∩) O ~ in fact, you see this article that I wrote late at night the day before, had wanted to speak directly to the basic types and variables, but it feels too abrupt, so the first article to briefly explain some of the basic concept, hope you will enjoy it.

Howl puffs public micro-channel front end (Geek-Fun)

Guess you like

Origin www.cnblogs.com/homehtml/p/12610528.html