operators in java script

15
Operators in JavaScript - Computer activity Made by : Abhinav Somani

Upload: abhinav-somani

Post on 15-Apr-2017

67 views

Category:

Career


0 download

TRANSCRIPT

Page 1: Operators   in  java script

Operators in

JavaScript -Computer activity

Made by : Abhinav Somani

Page 2: Operators   in  java script

WHAT IS AN OPERATOR?

• Operator  in java is a symbol that is used to perform operations. There are many types of operators in java such as unary operator, arithmetic operator, relational operator, shift operator, bitwise operator, ternary operator and assignment operator.

Page 3: Operators   in  java script

Types of operators • Arithmetic operators • Assignment operators • Comparison / Relational

operators • Logical operators• String operators • Conditional operators

Page 4: Operators   in  java script

Arithmetic Operators

• Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/).

Page 5: Operators   in  java script

• ARITHMETIC OPERATORS ARE USED TO PERFORM ARITHMETIC ON NUMBERS (LITERALS OR VARIABLES).

OPERATOR DESCRIPTION + ADDITION

- SUBTRACTION * MULTIPLICATION

/ DIVISION % MODULUS ++ INCREMENT

-- DECREMENT

Page 6: Operators   in  java script

OPERATORS AND OPERANDS• The numbers (in an arithmetic operation) are called operands.• The operation (to be performed between the two operands) is

defined by an operator.Operand Operator Operand 100 + 50

• The addition operator (+) adds numbers:• Adding

var x = 5;var y = 2;

var z = x + y; • The multiplication operator (*) multiplies numbers.• Multiplying

var x = 5;var y = 2;

var z = x * y;

Page 7: Operators   in  java script

• The subtraction operator (-) subtracts numbers.

• Subtracting-var x = 5;var y = 2;

var z = x - y; • The division operator (/) divides

numbers.• Dividing-

var x = 5;var y = 2;

var z = x / y;

Page 8: Operators   in  java script

• The modular operator (%) returns the division remainder.• Modulus

var x = 5;var y = 2;

var z = x % y; • The increment operator (++) increments numbers.• Incrementing

var x = 5;x++;

var z = x;• The decrement operator (--) decrements numbers.• Decrementing

var x = 5;x--;

var z = x;

Page 9: Operators   in  java script

JavaScript Comparison and

Logical Operators• Operator Description == equal to === equal value and equal

type != not equal !== not equal value or not

equal type > greater than < less than >= greater than or equal

to <= less than or equal to ? ternary operators

Page 10: Operators   in  java script

JAVASCRIPT ASSIGNMENT OPERATORS• The basic assignment operator is equal ( = ),

which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x . The other assignment operators are usually shorthand for standard operations, as shown in the following definitions and examples.

• Assignment operators assign values to JavaScript variables.

Operator Example Same As = x = y x = y

+ = x += y x = x + y -= x -= y x = x – y

*= x *= y x = x * y /= x /= y x = x / y

%= x %= y x = x % y

Page 11: Operators   in  java script

• The = assignment operator assigns a value to a variable.

• Assignmentvar x = 10;

• The += assignment operator adds a value to a variable.• Assignment

var x = 10;x += 5;

• The -= assignment operator subtracts a value from a variable.

• Assignmentvar x = 10;

x -= 5;

Page 12: Operators   in  java script

• The *= assignment operator multiplies a variable.• Assignment

var x = 10;x *= 5;

• The /= assignment divides a variable.• Assignment

var x = 10;x /= 5;

• The %= assignment operator assigns a remainder to a variable.

• Assignmentvar x = 10;

x %= 5;

Page 13: Operators   in  java script

JavaScript String Operators• The + operator can also be used to

add (concatenate) strings.• Example

txt1 = "John";txt2 = "Doe";

txt3 = txt1 + " " + txt2; The result of txt3 will be:John Doe

Page 14: Operators   in  java script

• The += assignment operator can also be used to add (concatenate) strings:• Example txt1 = "What a very ";

txt1 += "nice day";The result of txt1 will be:What a very nice day

Page 15: Operators   in  java script