# JavaScript Tutorial – Operators & IF-Else Statement

JavaScript Tutorial – Operators & IF-Else Statement

Operators

The Arithmatic Operators:

The Arithmetic Operators are used with numeric operands and returns a numerical value. There are following arithmatic operators supported by JavaScript language:

Let assume variable a=5 and variable b=10.

The Unchained Tour offers the java training with placements, and if you’re from Chennai make sure to check them out for your Java requirements

Operator

Description

Example

+

a + b = 15

-

Subtraction

a - b = -5

*

Multiplication

a * b = 50

/

Division

b / a = 2

%

Modulus (division remainder)

b % a = 0

++

Increment

a++ = 6

--

Decrement

a-- = 4

The Assignment Operators:

There are following assignment operators supported by JavaScript language:

Let assume variable a=20 and variable b=10.

Operator

Example 1

Same As Example 1

Result

=

a=b

a = 10

+=

a+=b

a=a+b

a = 30

-=

a-=b

a=a-b

a = 10

*=

a*=b

a=a*b

a = 200

/=

a/=b

a=a/b

a = 2

%=

a%=b

a=a%b

a = 0

The Comparison Operators:

There are following comparison operators supported by JavaScript language:

Let assume variable a=2 and variable b=3.

Operator

Description

Example

Result

==

is equal to

a == b

is not true

!=

is not equal

a != b

is true

>

is greater than

a > b

is not true

<

is less than

a < b

is true

>=

is greater than or equal to

a >= b

is not true

<=

is less than or equal to

a <= b

is true

The Logical Operators:

There are following logical operators supported by JavaScript language:

Let assume variable a=5 and variable b=8.

Operator

Description

Example

Result

&&

and

(a && b)

is true

||

or

(a || b)

is true

!

not

!(a && b)

is false

IF-Else Statement

### JavaScript If Statement

·        If statement is used to make a decision according to a given condition. The if statement evaluates the expression, if the value of expression is true then the instruction is executed.

### Syntax:

```  if (expression){
Execute statement if expression is true
}
```

### Example:

```  <script type="text/javascript">
<!--
var a = 10;
if( a > 7 ){
document.write("IF condition is fulfilled");
}
//-->
</script>
```

### JavaScript If - Else Statement

·        If statement is used to make a decision according to a given condition. The if statement evaluates the expression, if the value of expression is false then the else block is executed.

### Syntax:

```  if (expression){
Execute statement if expression is true
} else {
Execute statement else if expression is false
}
```

### Example:

```  <script type="text/javascript">
<!--
var a = 10;
if( a > 7 ){
document.write("IF condition is true");
} else {
document.write("IF condition is false");
}
//-->
</script>
```

### Syntax:

```  if (condtion 1 ){
Execute statement if condtion 1 is true
} else if (condtion 2 ){
Execute statement if condtion 2 is true
} else if (condtion 3 ){
Execute statement if condtion 3 is true
}  else {
Execute statement if all conditions are false
}
```

### Example:

```  <script type="text/javascript">
<!--
var a = "london";
if( a == "boston" ){
document.write("Boston city");
} else if(a == "paris" ){
document.write("Paris city");
} else if(a == "berlin" ){
document.write("Berlin city");
} else {
document.write("City names do not match");
}
//-->
</script>
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.56531566,"math_prob":0.9696369,"size":3213,"snap":"2020-10-2020-16","text_gpt3_token_len":854,"char_repetition_ratio":0.13960735,"word_repetition_ratio":0.2580071,"special_character_ratio":0.28882664,"punctuation_ratio":0.08787346,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9993625,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-18T04:04:02Z\",\"WARC-Record-ID\":\"<urn:uuid:f82f1024-69ed-4109-89a1-4e3d450f92a4>\",\"Content-Length\":\"11405\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2a418aa6-6212-4341-96c1-669a0dffc365>\",\"WARC-Concurrent-To\":\"<urn:uuid:f4834dc3-44a6-4de8-bccd-f6bd197084c1>\",\"WARC-IP-Address\":\"149.154.164.13\",\"WARC-Target-URI\":\"https://telegra.ph/JavaScript-Tutorial--Operators--IF-Else-Statement-10-24\",\"WARC-Payload-Digest\":\"sha1:P45QOI77FUHHW26VKFN3IH4UHYL3MSLO\",\"WARC-Block-Digest\":\"sha1:PHVC5YVTYCJEFXCNQSZZZMMZY3G6L6F3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875143505.60_warc_CC-MAIN-20200218025323-20200218055323-00408.warc.gz\"}"}