please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 4 Next
 

4. Expressions and Operators

Contents:
Expressions
Operator Overview
Arithmetic Operators
Comparison Operators
String Operators
Logical Operators
Bitwise Operators
Assignment Operators
Miscellaneous Operators

Expressions and operators are fundamental to most programming languages. This chapter explains how they work in JavaScript. If you are familiar with C, C++, or Java, you'll notice that expressions and operators in JavaScript are very similar, and you'll be able to skim this chapter quickly. If you are not a C, C++, or Java programmer, this chapter will teach you what you need to know about expressions and operators in JavaScript.

4.1 Expressions

An expression is a "phrase" of JavaScript that a JavaScript interpreter can evaluate to produce a value. Simple expressions are constants (e.g., string or numeric literals) or variable names, like these:

1.7                               // a numeric literal
"Oh no!  We're out of coffee!"    // a string literal
true                              // a Boolean literal
null                              // the literal null value
i                                 // the variable i
sum                               // the variable sum

The value of a constant expression is simply the constant itself. The value of a variable expression is the value that the variable refers to.

These expressions are not particularly interesting. More complex (and interesting) expressions can be created by combining simple expressions. For example, we saw that 1.7 is an expression and i is an expression, so the following is also an expression:

i + 1.7
The value of this expression is determined by adding the values of the two simpler expressions. The plus sign in this example is an operator that is used to combine two expressions into a more complex expression. Another operator is - which is used to combine expressions by subtraction. For example:

(i + 1.7) - sum
This expression uses the - operator to subtract the value of the sum variable from the value of our previous expression i + 1.7. JavaScript supports a number of other operators, besides + and -, which we'll learn about in the next section.


Previous Home Next
Data Type Wrapper Objects Book Index Operator Overview

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/JAVA/SCRIPT/definitive/ch04_01.htm, 6KB, , updated: 2019/10/14 15:00, local time: 2024/12/1 11:23,
TOP NEW HELP FIND: 
3.147.53.90:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://ecomorder.com/techref/language/JAVA/SCRIPT/definitive/ch04_01.htm"> [Chapter 4] Expressions and Operators</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .