(5) JavaScript expressions

Source: Internet
Author: User

Expressions for JavaScript

An expression is a collection of statements that, like each group, evaluates to a single value. The result is then grouped by JavaScript into one of the following data types: Boolean, number, String, object, and so on.

An expression can be a number or a variable, or it can contain many variable keywords and operators that are concatenated together. For example , the expression x/Y, respectively, the values of the free variables × and y are 10 and 5, the output is the number 2, but there is no definition when the Y value is 0, the assignment of an expression and the definition of the operator and the value of the definition field is associated.

1. Assignment expression

The expression syntax for an assignment is:"variable assignment operator expression", which is combined from right to left during the calculation.

Case Explanation:

<!DOCTYPE HTML> <Head> <Metahttp-equiv= "Content-type"content= "Text/html;charset=utf-8"/> <Metaname= "keywords"content= "JavaScript expressions, Getting started with JavaScript"> <Metaname= "description"content= "Lao Luo Lake"> <title>An assignment expression</title> </Head> <Body> <Scripttype= "Text/javascript"> varx=Ten; document.write ("<p> The value of the current variable x is: x="+x); X+=x-=x*x; document.write ("<p> After executing the statement x+ = x =x*x, the value of the variable x is: x=" +x); vary=Ten; document.write ("<p> The value of the current variable y is: y="+y); Y+=(y-=y*X); document.write ("<p> Executes the statement y+= (Y-=y*y, the value of the variable y is; y="+x); </Script> </Body></HTML>

2. Arithmetic Expression is the statement of the JavaScript that is concatenated with the arithmetic operator . such as: A+b+c, 15-y;, x*y;, A/b;, 100%3; An expression that is a valid arithmetic operator.

3. Boolean expression: Boolean expressions are used to determine whether a condition or expression is true. The result can only be true or false. look at the case explanation:

<!DOCTYPE HTML> <Head> <Metahttp-equiv= "Content-type"content= "Text/html;charset=utf-8"/> <Metaname= "Author"content= "Lao Luo Lake"> <Metaname= "Keywords"content= "JavaScript expression, JavaScript primer, JavaScript"> <title>Boolean expression</title> </Head> <Body> <Scripttype= "Text/javascript"> functioncheckyear () {varTxtyearobj=document.all.txtYear;//text Box Object    varTxtyear=Txtyearobj.value; if((Txtyear== NULL) ||(Txtyear.length< 1)||(Txtyear< 0))    { //text box value is emptyWindow.alert ("Please enter the correct year in the text box! ");        Txtyearobj.focus (); return; }     if(IsNaN (txtyear)) {//user input is not a numberWindow.alert ("the Year must be an integer number! ");        Txtyearobj.focus (); return; }     if(Isleapyear (txtyear)) Window.alert (Txtyear+"year is the Olympic year! "); ElseWindow.alert (Txtyear+"year is not Olympic year! "); } functionisleapyear (yearval)//Judging whether the Olympic year {   if((Yearval%  - == 0)&&(Yearval%  - == 0))      return true; if(Yearval% 4 == 0)return true; return false; } </Script> <H3>Boolean expressions are used to determine whether a condition or expression is true. The result can only be true or false.</H3> <formAction="#"name= "Formyear">Please enter the current year:<inputtype= "txt"name= "Txtyear"> <P>Please click on the button to determine whether it is an Olympic year:</P> <inputtype= "button"value= "button"onclick= "Checkyear ()"> <BR/> <BR/> <P>In case of multiple use Boolean expression to judge the value, run the code, enter 2019 in the Displayed text box, click the "OK" button, the system determines whether the text box is empty, and then determine whether the text box entered a valid value, and finally determine whether the Olympic year and pop up the corresponding prompt box.</P> <form> </Body></HTML>

4. String expression:

A string expression is a JavaScript statement that operates on a string . A JavaScript string expression can only use "+" and "+ =" two string operators. If you have both a number and a string in the same expression, and you do not have a method to convert the string to a number, the return value must be a string type. omitted here ...

/* The content section above comes from "JavaScript starts from scratch", "W3school offline manual Simplified Chinese version" and individual study notes, this article final explanation right belongs to oneself all! */

(5) JavaScript expressions

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.