JavaScript programs are not always written in a straight-line, sequential manner. Most problems you solve using a computer require that the program be able to make choices about which lines of code to execute. For example, a payroll program will have to decide if an employee should be paid straight time or overtime for their work, depending on how many hours they worked in a week or pay period.

JavaScript provides two major constructs for making selections in code. The first of these constructs is the if statement. The other construct is the conditional operator. This article will discuss how to form the various types of if statements you can have in JavaScript and then end with a discussion of the conditional operator.

The Relational Operators

Before I can talk about selection structures, I need to cover how JavaScript programs compare things. Comparisons in JavaScript are done using the relational operators. The relational operators compare two values for different relations. The relational operators are:

#learning-javascript #javascript #javascript-development

Learning JavaScript: Selection Structures
2.05 GEEK