JS Introduction, JS How to implement input and output statements, comments

Source: Internet
Author: User

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

    1. JavaScript a literal-translation scripting language
    2. JavaScript is a lightweight programming language.
    3. JavaScript is a programmatic code that can be inserted into an HTML page.
    4. 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

    1. <script> and </script> will tell JavaScript where to start and end;
    2. 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:

    1. 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>
    1. Use the Click event onclick= "Myclick" alert ("Hello world! ”);
JavaScript statements, comments

JavaScript statements:

    1. 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:

    1. When writing JavaScript statements, be aware of whether to turn off the case toggle key.

Example: function getElementById and getElementById are different

    1. Space

JavaScript ignores extra spaces, and you can add spaces to your script to improve its readability

Example: var username = "Weiker" var username= "Weiker"

    1. 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.

    1. Single-line comments start with//
    2. JavaScript Multiline comments, multiline comments start with/*, End with */
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.