write statement: General Syntax: document write ("string " + var); . . Type casting in JavaScript. Type conversion is the act of converting one data type into a different data type which is also called as casting.
In JavaScript there are two type of casting, • Implicit casting and • Explicit casting Implicit casting occurs automatically in JavaScript when you change the data stored in a variable: Chapter Pages . JavaScript Operators and Expressions An operator combines the values of its operands in some way and evaluates to a new value. Operators are used for JavaScript’s arithmetic expressions, comparison expressions, logical expressions, assignment expressions. An expression is a phrase of JavaScript that a JavaScript interpreter can evaluate to produce a value.
The data types are used directly as literals or within variables in combination with simple operators, such as addition, subtraction, and so on, to create an expressions. An expression is a code fragment that can be evaluated to some data type the language supports. An expression is simply one or more variables and/or constants joined by operators. An expression is evaluated and produces a result.
The result of all expressions may be either an integer or floating-point value or Boolean value. There are three types of expressions as follows, • Arithmetic expressions • Relational expressions • Logical expressions . . Arithmetic Operators JavaScript supports all the basic arithmetic operators like addition (+), subtraction (–), multiplication (*), division (/), and modulus (%, also known as the remainder operator).
Table: . – Arithmetic Operators Arithmetic Operator Meaning Example Result + Addition var sum = + Variable sum = - Subtraction var diff = – Variable diff = * Multiplication var prod = * Variable prod = / Division var res = / Variable res = . % Modulus operator var rem = % Variable rem = (remainder) <Html> <Head> <Title>Demo Program – To test Arithmetic Operators in JavaScript </Title> </Head> <Body> <script language="javascript" type="text/javascript"> Illustration . Using Arithmetic Operators Chapter Pages