nagging

The previous record is from an old textbook, too old to see HTML5. I recently changed to a new textbook, the Art of JavaScript DOM Programming (2nd edition), so this blog post updates the basic syntax.

How to write an HTML file

The introduction of JavaScript in HTML can be written between , and can be written in the back. You can write it directly in an HTML file or in a separate JS file. It is recommended to write at the end of the document, before , to speed up the browser.

<! DOCTYPE html> <html> <head> <meta charset="utf-8">
        <title>A new example</title>
    </head>
    <body>
        <script src="example.js"></script>
    </body>
</html>

Copy the code

grammar

Var beatles = Array(4); var beatles = Array("John"."Paul"."Geogle"."Ringo");
var beatles = ["John"."Paul"."Geogle"."Ringo"]; Var lennon = Array(); lennon["name"] = "John";
lennon["year"] = "1990";
lennon["living"]  = false; Var lennon = Object(); lennon.name ="John";
lennon.year = 1990;
lennon.living = false; // Simple object creation var lennon = {name:"John", year:1990, living:false}; Var Beatles = new Array(); // This statement actually creates an instance of an Array object, JS, Math,Date and other built-in objects // host object // There are predefined objects provided by the browser as host objects, such as Form,Image,ElementCopy the code