Review Sheets - JavaScript - Logical Operators | CMSC 198N, Study notes of Computer Science

Material Type: Notes; Professor: Padua-Perez; Class: INTRO COMP PROG VIA WEB; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-lf2-1
koofers-user-lf2-1 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
ANNOUNCEMENTS
No posting of code in the forum.
You must implement programming projects
by yourself.
pf3
pf4
pf5

Partial preview of the text

Download Review Sheets - JavaScript - Logical Operators | CMSC 198N and more Study notes Computer Science in PDF only on Docsity!

ANNOUNCEMENTS

 No posting of code in the forum.

 You must implement programming projects

by yourself.

JAVASCRIPT (LOGICAL OPERATORS)

 Used with comparison operators to create more complex expressions.

 Operators

 Logical and (&&) – expr1 && expr

 Expression is true if and only if both expressions are true

otherwise is false.  Example: LogicalOp1.html  Logical or (||) – expr1 || expr  Expression is false if and only if both expressions are false otherwise is true.  Example: LogicalOp2.html  Logical Not (!) – !expr  Inverts the boolean value of the expression.

CASCADED IF STATEMENT IDIOM

 You can combine if statements to handle different cases.  This approach to organize if statements to handle different cases is called the Cascaded If Statement.  Cascaded If statement general form:

If (expr1) // Statement is executed if expr1 is true else if (expr2) // Statement is executed if expr2 is true else if (expr3) // Statement is executed if expr3 is true else // If none of the above expressions is true

 Notice it is not a JavaScript statement.  Once one of the cases is executed no other case will be executed.  You can use { } to enclose more than one statement.  Example: See CascadedIf.html

WHILE STATEMENT

 while statement – Control statement which allows JavaScript

to repeat a set of statements.

 Basic Form

while (expression)

statement // executed as long as expression is true

 If you want to execute more than one statement then use a

set of { } to enclose the statements.

 You can have other types of statements (including whiles) in

a while.

 Example: SqrtTable.html