JavaScript BASICS (1): Basic javascript knowledge

Source: Internet
Author: User

JavaScript BASICS (1): Basic javascript knowledge

/*
JavaScript Basics
* ****** This summary is written in DW. for debugging convenience, write comments to the sections that affect the test ****/


// 1. How to place JavaScript? // // <Body>
// <Script type = "text/javascript"> the syntax here is to enable the old browser to recognize
// Write the JavaScript statement here
// For example:
Document. write ("hello world"); // display hello world on the page
// *** Note that this will overwrite the original content on the page.
/// </Script>
/// </Body>
// </Html>

// 2. Location differentiation // JavaScript statements can be placed in any part of the HTML document. Generally, we will put them in a few places.
// A) <body> <script> JavaScript statement </script> </body>
// This part of code will be executed during page loading
// B) // This part of the code will be executed during the call to ensure that the code you need has been loaded during the call.
// C) the two parts can exist at the same time.
// D) independently create xxx. js files and connect them within HTML. External files cannot have <script> labels.
// <Script src = "js file location"> </script>

// 3. Comments // a) single-line comments (// The most comments in this article)
// B) multi-line comments (/* comments */)

// 4. variables (container for storing information) // a) variables in JavaScript can be directly used without prior declaration.
// B) variables in JavaScript are case sensitive and must start with letters or underscores
// C) variables can be declared using var or repeated declarations.
// For example, var x = 1; var x;
// After the declaration, the original value of the variable will not be lost.

// 5. JavaScript Arithmetic Operators // Arithmetic Operators are used to perform arithmetic operations between variables and/or values.

// Given y = 5, the following table explains these arithmetic operators:
// Operator Description Example result
// + Add x = y + 2 x = 7
//-Subtraction x = y-2 x = 3
// * Multiply x = y * 2 x = 10
/// Except x = y/2 x = 2.5
// % Returns the remainder (Reserved integer) x = y % 2 x = 1
// ++ Accumulate x = ++ y x = 6
// -- Decrease x = -- y x = 4

// 6. JavaScript assignment operation // set x = 10 and y = 5. The following table describes the assignment operators:
// The operator example is equivalent to the result
// = X = y x = 5
// + = X + = y x = x + y x = 15
//-= X-= y x = x-y x = 5
// * = X * = y x = x * y x = 50
/// = X/= y x = x/y x = 2
// % = X % = y x = x % y x = 0

// 7. Use of + // + not only can be used for computation, but also can be used to connect strings
// For example, x = 5 + 5; (the result is 10) x = "5" + "5"; x = 5 + "5 "; x = "5" + 5; (the result is 55, string)

// 8. JavaScript comparison operators // comparison operators are used in logical statements to determine whether variables or values are equal.
// Given x = 5, the following table explains the comparison operators:
// Operator Description Example
// = Equal to x = 8 is false
// === Full (Value and type) x === 5 is true; x === "5" is false
//! = Not equal to x! = 8 is true
//> The value greater than x> 8 is false.
// <Less than x <8 is true
// >=Greater than or equal to x >=8 is false
// <= Less than or equal to x <= 8 is true

// 9. logical operators // logical operators are used to determine the logic between variables or values.
// Given x = 6 and y = 3, the following table describes the logical operators:

// Operator Description Example
// & And (x <10 & y> 1) is true
// | Or (x = 5 | y = 5) is false
//! Not! (X = y) is true

// 10. Conditional operators // statements whose results are logical values? Value 1: Value 2


Not yet to be continued .... Correction

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.