One Pager Cheat Sheet
- We will learn about controlling the behavior of a program using
if/else
andtry/catch
statements to establish itscontrol flow
. - The control flow of a program is the order of execution of code elements, taking different decisions based on
if/else
andtry/catch
statements to handle errors and exceptions. If/Else Statements
provide a way to control program execution, by defining different flows depending on the conditions, such as in the form of aflow chart diagram
.- Using the
if
andelse
keywords, JavaScript allows for conditions to be evaluated with the syntaxif (expression) { statement; }
, enabling developers to create ascope
within thecurly braces
for thestatement
to be evaluated against the givenexpression
. - We can use the
if-else if-else
structure to determine a number's value in JavaScript using multipleif
statements. - An
if
condition is essential forelse if
andelse
statements to work, but it is possible to have anif
condition that stands alone. - There is
no limit
to the number of statements that can be included under anif
block. - The code needs a
boolean expression
enclosed in round brackets( )
in theif
block in order to be evaluated by the compiler. - Using
try/catch
statements allow the programmer to handle errors that occur during the execution of the program. - Using the
try
andcatch
keywords, a JavaScript program can handle errors by running the statements in thecatch
block, preventing the program from halting. - No, we cannot have a
catch
block without atry
block because it is a syntax structure in JavaScript that requires both. - The
try
block will attempt to execute the return statement, producing the output of 1 and thecatch
block will never be used as there was noerror
to handle. - We can control the flow of execution in a program and adapt to uncertain conditions using
if/else
andtry/catch
statements, which is necessary for many complex applications such as in artificial intelligence.