JavaScript is an interpreted language , not a compiled language like Java or C + +. The JavaScript instructions are passed to the browser in plain text and then interpreted in turn for execution. They do not have to be "compiled" into machine code that is understandable only by computer processors.
Introduction to DOM
The Document Object Model (DOM) is an abstract representation of the document and its contents.
Each time the browser loads and displays the page, it needs to interpret the HTML source code that makes up the page. During the parsing process, the browser creates an internal model that represents the contents of the document, which is the DOM. This model is referenced when the browser renders the visible content of the page. We use JavaScript to access and edit the various parts of the DOM model to change the way the page is displayed and how it interacts with the user.
window and Document objects
In the DOM, the elements of the page have a logical, hierarchical structure, like a tree structure with parent objects and sub-objects. At the top of this hierarchy is the browser window object, which is the root of all objects in the DOM tree.
Any method call that does not explicitly indicate an object will be directed to the window (e.g. window.alert () = = alert ()).
The Window object has some sub-objects (Document,location,history,navigator, and so on), where the document object is most frequently used. Any HTML page loaded by the browser creates a document object, including all of the HTML content and other resources that make up the page display. This information can be accessed in the form of a parent-child object using JavaScript. These objects all have their own properties and methods.
Dom objects and built-in objects
In the methods of the Window object, some are specifically designed to handle input and output information: alert (), confirm (), prompt ();
Select elements by ID: document.getElementById ("Id_name");
The innerHTML property can read or set HTML content inside a particular page element.
Access browser history using the Window.history object.
The Location object contains the URL information for the page that is currently loaded, and the page is refreshed using the site object navigation.
The Navigator object contains the data for the browser program itself.
Math Object Simplification operation
Floor (num): Rounding down
Ceil (num): Rounding up
Round (num): Rounding
Random (): Generate randomly 0 to 1 numbers
Data type
JavaScript is a weakly typed programming language, meaning that JavaScript variables can be interpreted as different types in different contexts.
In JavaScript, you can use a variable without having to declare the data type of the variable beforehand, and the Javas interpreter will make the judgment that it deems correct according to the situation. If we were to save a string in a variable and later want to use it as a numeric value, it would be perfectly doable in JavaScript, provided that the string does contain the contents of "like" values (such as "200px", "59").
Array
Create array: 1,var MyArray = new Array (); 2, var myArray = [];
An array has a length property, and its value is always 1 larger than the maximum index value, even if the actual number of elements in the array is not that large.
JavaScript easy to Leak point