Programming Examples

Are you a Programmer or Application Developer or a DBA? Take a cup of coffee, sit back and spend few minutes here :)

Tag Archive for ‘prompt’

JavaScript 004 – parseInt & NaN

JavaScript parseInt

In JavaScript, a variable can hold any data type. Sometimes, we need to convert the string representation of a number to an integer or float. For example, data submitted by web form comes in string format, even user entered the data in number format. We can say an age submitted by the user comes as a string. JavaScript, need to convert this as a number. Once data is converted to a number, it can involve in mathematical expressions

Continue Reading →

JavaScript 002 – Calculation via Expression

JavaScript Expression Evaluation

In JavaScript, you can perform arithmetic by forming the expressions. When making the expression, you can use binary operators like addition (+), subtraction (-), multiplication (*) and division (/). We call them as a Binary Operator as it operates on two variants. Now look at the expression below:

10 – 4 * 2

You may expect the result is 12. But the result is 2. Because here Operator Precedence comes into picture. The operator * and / play higher priority than the + and – operators. In the above expression, the binary operation * is figured out on the operands 4, 2. Then the binary operation minus is done on the operand 10 and 8 giving up the result as 2. In the above expression, we used only the constant values. But one can use the variables also as an operand.

Continue Reading →