2017-3-28 JavaScript Basics, syntax

Source: Internet
Author: User

Front Three Musketeers:

html+css+js(HTML determines what is on the page, CSS determines how things are placed, JS determines the function of things)

JS Definition:

JS is a scripting language that requires a host file, and its host file is an HTML file.

js function:Perform data operations
Control some features of the browser
Control elements
+ Properties
+ Style
+ Content

Reference Location:
Inline JS:You can place it anywhere in the HTML file:HeadInsideBobyInsideIt's all right behind you. It is recommended to write the JS code at the bottom of the page.
<script type= "Text/javascript" ></script>
External JS:Write the JS code to a file at the end of the. js, and then refer the file to the HTML file.
Embedded JS:Wait until the event.

three common dialog boxes:  1, alert (); Warning dialog box. The function is: Pop up a warning dialog box, for example: Alert ("error occurred");

2, confirm (); Determines the dialog box. The function is: Pop Up an optional OK dialog box, click OK, it returns true; Click Cancel to return False, the available variables to receive;

For example: Confirm ("OK to exit?") ");

3, prompt (); Enter the dialog box. The function is to pop up a dialog box that allows you to enter content. For example: Prompt ("Enter a number in the bar", "can only be a number Oh");

=================================================================================================

JS Syntax:

1. Basic Data type: string, Decimal, Integer, Time Date, Boolean, etc.

2, variables: All types of variables are defined by VAR.

3, type conversion: automatic conversion and casting, generally with cast. parseint;parsefloat;

Determine if it is a valid number type:IsNaN (); If yes, returns False if not, returns True.

4, Operator: math Operator: +-*/% + +--;

Relational operators: = = = = >= <= > <;

Logical operator:&& | | !;

Other operators: + = = *=/=%=?:;

5, statements: divided into sequential statements, branch statements, circular statements; (usage with C #)

6. Array:

definition of the array:var a=new array (); Its length is dynamic, which can be placed in any type of element;

Assignment of array elements:a[0]=123; a[1]= "Hello";

Array value:a[i];

Array properties:a.length; number of array elements, length.

method:a.sort (); Sort the array, sorted by the first character. A.reverse (); Flip an array

7. Function:

function Four elements: input, output, function name, function body

define functions:functionA (formal parameter) {function body} function return value can be var type or return value

function Call: A (formal parameter)

2017-3-28 JavaScript Basics, syntax

Related Article

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.