JavaScript Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 2.00

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) 2008 by Dr. Herong Yang, http://www.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

Sections in This Chapter

Primitive Data Types - Numbers, Strings, and Booleans

Numeric Value Literals

String Literials

Declaring Variables - "var" Statements

Operators and Expressions

Operators and Expressions - Examples

Dr. Herong Yang, updated in 2008
Operators and Expressions - Examples