Basic syntax for JavaScript

Source: Internet
Author: User
Tags html tags

1, the basic structure of the script is as follows:

<script language= "JavaScript" >          <!--javascript statements;-->       

Tip: You typically place core script statements between tags

The document.write () method is used for page output display information.

Question: Why does the browser display the contents of the script rather than the results of the script execution?
A, omission start or end of <script>. b, the extension is not. html or. htm. C, the browser does not support JS script.

2, the principle of implementation:
Client requests a page with JavaScript

  Download pages with javascript from the server side  

Client-side parsing of HTML tags and JavaScript scripts

3. Basic syntax:
var a valid variable name;
Variable names cannot use keywords. Multiple variables can be separated by commas.

The operation symbol is the same as in Java

if (expression) {}else{}

for (initialize; condition; increment or decrement) {}

while (condition) {}

switch (expression)
{Case constant value 1:javascript statement;

Case constant Value 2:javascript statement;

Default:javascript statement;

}
Type: Number/null/boolean/string/object/undefinde

Type conversions: Mastering the Parsefloat () and parseint () functions.

Focus on defining functions: Function function name (argument list) {}

Note: You can also have no parameters
Call Function: Event name = "function name ()"
Get form data: document. Table sole name. form element name. value

Example 1:function Calcu () {
var Numb1=document.calc.num1.value;

var Numb2=document.calc.num2.value;

var total=parsefloat (NUMB1) *parsefloat (NUMB2);

Document.calc.result.value=total; }        

<form name= "Calc" >

<input name= "Result" type= "text" size= ">"
<input name= "getanswer" type= "button" id= "Getanswer" onclick= "CALCU ()" >

</form>

Example 2: Print the inverted pyramid line

var i = 25;

while (i>0) {
Docment.write ("

i=i-5;

}
for (Var j=5;j<30;j=j+5) {
Docment.write ("When defining functions, note:
Formal parameters: The parameters defined for a function when the function is defined, which represents the type and location of the parameter.

Actual parameter: The parameter value passed to the function when the function is called.

When called: passes the value of the argument to the parameter.

Function names are strictly case-sensitive.

Multiple parameters are separated by commas, and you must specify a type-compatible value for each parameter separated by commas when you want to invoke the function.

If you need to return a result, use the return statement.

Basic syntax for JavaScript

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.