JavaScript expressions and operators Free Web Design Tutorials
Home   HTML CSS JavaScript PHP MySQL Usability Glossary
JavaScriptBasicsRunning a ScriptVariablesJavaScript Expressions and OperatorsExpressions and OperatorsObjects.Properties.MethodsThe Date ObjectStringsRegular ExpressionsDefining RegExp PatternsBranches and ConditionsLoopsArraysArray MethodsSorting ArraysUser-Defined FunctionsCookiesWindowsFrames

Home > JavaScript > Expressions and Operatorsprinter version

Expressions and Operators

Expressions in JavaScript are formed from literal values, operators and the return values of function calls.

An example of an expression with two literals separated by an operator would be my_var = 4 + 5;.

Although it's not possible to multiply strings, JavaScript will try to convert expressions to an appropriate type. Therefore my_var = 4 * "5" is legal and will return the numeric value 20.

Operator Precedence

In common with other programming languages, JavaScipt gives precedence to multiplication and division over addition and subtraction etc.

Memorising and using the order of operator precedence usually leads to mistakes and unreadable code therefore the easiest way is to use parenthesis.

For example my_variable = 3 + 4 * 2; means that my_variable = 11;. However, my_variable = 3 + (4 * 2); is less error prone and much clearer.

Previous - JavaScript Variables Previous - Variables     Next - Objects, Properties and Methods Next - JavaScript Objects, Properties and Methods


Privacy | Terms | Contact | Links | Sitemap | RSS Feeds RSS and JavaScript Feeds
©2009 www.webdesignworkmate.co.uk all rights reserved 
Design and Production by smallbizonline website design © 2000-2009
Valid HTML 4.01! Level Double-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0Valid CSS!
Recommended Reading
Javascript the definitive guide

Javascript and DHTML cookbook

Pro javascript techniques

simply javascript