Operators and Expressions - Examples

This section provides a JavaScript tutorial example on using arithmetic, comparison, bitwise, and assignment operators.

Based on the description of operators and expressions given in the previous section, here is a JavaScript tutorial example that shows you different types of operators:

<html>
<!-- Operators.html
   Copyright (c) 2013 by Dr. Herong Yang, herongyang.com
-->
<head><title>Operators and Expressions</title></head>
<body>
<pre>
<script type="text/javascript">
   document.write(10/3);
   document.write('\n');
   document.write(10%3);
   document.write('\n');

   document.write(1>0);
   document.write('\n');
   document.write('Five'>'One');
   document.write('\n');

   document.write(10=='10');
   document.write('\n');
   document.write(10==='10');
   document.write('\n');

   document.write(1<<3);
   document.write('\n');
   document.write(8>>3);
   document.write('\n');

   var comment;
   document.write(comment='Assignment is expression');
   document.write('\n');
</script>
</pre>
</body>
</html>

The output of this sample JavaScript is:

3.3333333333333335
1
true
false
true
false
8
1
Assignment is expression

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

Data Types, Variables and Expressions

 Primitive Data Types - Numbers, Strings, and Booleans

 Numeric Value Literals

 String Literials

 Declaring Variables - "var" Statements

 Operators and Expressions

Operators and Expressions - Examples

 Flow Control Statements

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 Defining Your Own Object Types

 Inheritance of Properties and Methods through the Prototype Object Chain

 'jrunscript' - JavaScript Shell Command from JDK

 Using Functions as "Function" Objects

 Introduction to Built-in Object Types

 W3C's Document Object Model (DOM) Specifications

 References

 PDF Printing Version