Introduction to JavaScript
JavaScript is the most popular programming language in the world.
Can be used in HTML and the web, and more widely used in servers, PCs, laptops, tablets, smartphones and other devices
- JavaScript a literal-translation scripting language
- JavaScript is a lightweight programming language.
- JavaScript is a programmatic code that can be inserted into an HTML page.
- When JavaScript is inserted into an HTML page, it can be performed by all modern browsers.
is a dynamic type, a weak type, a prototype-based language, and a built-in support type.
JavaScript implements input and output
JavaScript Syntax:
The script in HTML must be between <script> and </script> tags, and the script can be placed in the <body> and
Two. Use <script> tags
- <script> and </script> will tell JavaScript where to start and end;
- The lines of code between <script> and </script> contain JavaScript:
<script> alert ("My first JavaScript"); document.write ("<p>this is a heading</p>"); </script>
JavaScript manipulating HTML elements
JavaScript is typically used to manipulate HTML elements:
- If you want to access an HTML element from JavaScript, you can use the document.getElementById (ID) method
Use the ID property to identify the HTML element:
<p id= "Demo" ></p><script type= "Text/javascript" > document.getElementById ("Demo"). innerHTML= "Wel Come to Weiker ' s blog! "; </script>
- Use the Click event onclick= "Myclick" alert ("Hello world! ”);
JavaScript statements, comments
JavaScript statements:
- A command issued by a JavaScript statement to a browser that tells the browser what to do.
Grammar:
<1> semicolons are used to separate JavaScript statements;
<2> usually we add semicolons at the end of each executable statement, and another use of semicolons is to write multiple statements in one line;
<3> currently can not take, the browser executable (with a semicolon to the concluding sentence is optional) but does not conform to the code specification;
Note:
<1> The browser executes each statement in the order in which it is written;
<2> JavaScript statements are combined as blocks of code, starting with the left curly brace, ending with a closing curly brace, and the block acting as a sequence of statements.
JavaScript is case-sensitive:
- When writing JavaScript statements, be aware of whether to turn off the case toggle key.
Example: function getElementById and getElementById are different
- Space
JavaScript ignores extra spaces, and you can add spaces to your script to improve its readability
Example: var username = "Weiker" var username= "Weiker"
- Wrapping lines of code
You can wrap lines of code in a text string with a backslash
Example: document.write ("Hello \
World! ");
JavaScript annotations can be used to improve the readability of your code:
JavaScript does not execute annotations
We can add comments to explain JavaScript, or to improve the readability of the code.
- Single-line comments start with//
- JavaScript Multiline comments, multiline comments start with/*, End with */
- You can also put the comment at the end of the line of code, var i = 5; Declare I and assign a value of 5 to it
--respect for the original, please do not reprint! ——
JS Introduction, JS How to implement input and output statements, comments