JavaScript syntax basics-Variables and functions

Source: Internet
Author: User

Three JavaScript syntax basics-Variables and functions

(a) Declaration and application of variables

Variables in JavaScript are very different from strongly typed languages such as Java and C, although there are strings, numbers, and other data types in JavaScript.

The structure of a variable declaration statement is a VAR reserved word plus an identifier, separated by a space between Var and the identifier.

The structure of an assignment statement is to add an equal sign between the variable and the value that needs to be assigned, for example, the meaning of a=1 is to specify the value of variable a as 1.

Variables can also be assigned at the time of definition, such as Var a=1.

PS: It is a good programming habit to declare before variables are used, which is useful for learning other languages such as Java in the future. Obsessive Compulsive disorder is a good habit.

(ii) Declaration and use of functions

A function is a piece of code that can do a certain function, accept several parameters, and return a result.

Usually in a complex programming, always according to the function to be completed, the program is divided into relatively independent parts, each part of a function, so that the parts are fully independent, the task is single, the program is clear, easy to read and easy to maintain.

A parameter is a value that is passed to or manipulated by a function, whose value can be a constant, variable, or other expression.

A JavaScript function encapsulates a program that may be used multiple times in a program and can be invoked as an event-driven result, thereby implementing a function that is associated with the event driver (emphasis).

Specific as follows "

* Definition of function

Function name (parameter)

{

function body;

return value;

}

* Function Description You can use a variable, a constant, or an expression as a parameter to a function call

* functions are defined by the keyword function

* The definition rules for function names are consistent with identifiers and are case sensitive

* Return value must use return

<! DOCTYPE html> with a JS page</title ><script type= "Text/javascript" >function  hello () {    var  hi;     var name=prompt ("What is your name?:", "Doriswowo");    Hi= "Hello" +name+ "!welcome to my space~~";    Alert (hi);    document.write (HI);} Hello (); //  </script>page content </body>

JavaScript syntax basics-Variables and functions

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.