in the event that announcement 

The if articulation executes a square of code if the contingent articulation inside a couple of enclosures assesses to genuine. The conditions ordinarily include examination of factors for balance or imbalance. Here is a basic precedent: 

var individual = { age: 33 }; 

on the off chance that (person.age >= 18) { 

caution ("Adult");/=> Adult 

caution ("Allowed to cast a ballot");/=> Allowed to cast a ballot 

The square of code that executes following the if-proclamation can be a solitary articulation or numerous announcements encased by wavy supports, {}. 

Shortcircuiting 

Every one of the parts of a consistent articulation probably won't be assessed. The articulation will be assessed just until the genuine or bogus ness of the whole articulation can be unambiguously decided. 

Let's assume we have an if-proclamation with two articulations: a <= 7 and b > 10. They are isolated by a || (or) administrator. 

var a = 4; 

var b = 5; 

on the off chance that (a <= 7 || b > 10) {/genuine 

alert("yes");/=> yes 

Since a = 4, the articulation (a <= 7) assesses to a genuine esteem. This implies the whole articulation will be valid, in any case whether b is more prominent than 10 or not. Assessing the second articulation (b > 10) isn't required thus JavaScript will skirt that. This is called shortcircuiting the articulation. 

JavaScript Built-in Types

on the off chance that… else proclamation 

The if-explanation may contain a discretionary else statement that indicates an elective strategy. The else provision is executed if the articulation in the if-proclamation is assessed to false. 

var secret phrase = "mystery"; 

in the event that (password.length >= 7) { 

alert("okay"); 

} else { 

alert("Number of characters in your secret phrase must be at any rate 7."); 

return false; 

in the event that… else if… else proclamation 

On the off chance that you have to test various conditions, if… else if… else is the thing that you can utilize. On the off chance that the condition related with the if explanation is valid, the announcements inside the if square are executed. On the off chance that the condition is false, each else-if explanation is assessed in the request in which they show up. At the point when a genuine else-if condition is discovered, the announcements inside that else-if square are executed. On the off chance that no else-if condition is assessed to genuine, the announcements inside the else square are executed. 

var age = 34; 

on the off chance that (age < 13) { 

alert("child");/=> tyke 

} else if (age < 19) { 

alert("adolescent");/=> immature 

} else { 

alert("adult");/=> grown-up 

How To Learn JavaScript

switch explanation 

As an option in contrast to countless .. else if .. else proclamations you can utilize a switch explanation which makes your code more compact and comprehensible. 

The switch catchphrase is trailed by an articulation you wish to assess. This articulation is alluded to as the control variable that controls the stream of program execution. This articulation is assessed and its esteem is contrasted with the esteem following every one of the case marks. When the coordinating case mark is discovered, the square of code contained inside that case is executed. The last proclamation in a square of code is quite often a break articulation that flags the finish of the square. 

You can indicate a default case which is discretionary. It is like the else provision of an if proclamation and is executed when none of the cases coordinate. There must be one 'default' mark for a switch proclamation. Despite the fact that default is discretionary, it is prescribed that you incorporate it as it handles any unforeseen cases. Here is a model: 

var account = 3; 

switch (account) { 

case 1: 

alert("Checking account");/=> Checking account 

break; 

case 2: 

alert("Savings account");/=> Savings account 

break; 

case 3 : 

alert("Business account");/=> Business account 

break; 

default: 

alert("Invalid account code"); 

break; 

Handling Errors in JavaScript: The Definitive Guide

Maintain a strategic distance from switch fail to work out 

You should end each case with an unequivocal break explanation. On the off chance that a break is missing, case articulations 'fail to work out' implying that the control will stream successively through ensuing case explanation. 

var account = 3; 

switch (account) { 

case 1: 

alert("Checking account");/=> Checking account 

break; 

case 2: 

alert("Savings account");/=> Savings account 

break; 

case 3: 

alert("Business account");/=> Business account (fails to work out) 

default: 

alert("Invalid account code"); 

break; 

In the above code, the break is missing on the off chance that 3, so control will fall through to the default case, and the yield will be both "Business record" and "Invalid record code", which is off base. 

Neglecting to include a break is a typical blunder and can make hard discover bugs. JSLint will report a missing break (or return or toss proclamation) when it distinguishes one. It does as such in light of the fact that most fall-throughs are unexpected. On the off chance that you purposefully actualize your rationale to utilize the fall-through methodology, archive it appropriately with the goal that other people who read your code don't get befuddled.

10 things to learn on the way to becoming a JavaScript Master
JavaScript Arrays
JavaScript Functions
JavaScript Loops
Handling Errors in JavaScript: The Definitive Guide