1. Operators
1.1 Ternary Operator
A Ternary Operator can be used to replace
if...else
statements in some situations.Syntax:
condition ? expressionIfTrue : expressionIfFalse
JAVASCRIPT
2. Conditional Statements
2.1 Switch Statement
A Switch statement is a conditional statement like
if...else
statement used in decision making.Syntax:
JAVASCRIPT
2.1.1 What happens if we forgot a break?
If there is no
break
statement, then the execution continues with the next case until the break
statement is met.JAVASCRIPT
3. Defining Functions
There are multiple ways to define a function.
- Function Declaration
- Function Expression
- Arrow Functions
- Function Constructor, etc.
3.1 Arrow Functions
An Arrow function is a simple and concise syntax for defining functions.
It is an alternative to a function expression.
Syntax:
JAVASCRIPT
3.1.1 Simple Expressions
In arrow functions, the
return
statement and curly braces are not required for simple expressions.JAVASCRIPT
3.1.2 One parameter
If there is only one parameter, then parentheses are not required.
JAVASCRIPT
3.1.3 No parameters
If there are no parameters, parentheses will be empty, but they should be present.
JAVASCRIPT
3.1.4 Returning Objects
JAVASCRIPT
Simple Expression
JAVASCRIPT
JavaScript considers the two curly braces as a code block, but not as an object syntax.
So, wrap the object with parentheses to distinguish with a code block.
JAVASCRIPT
Try out the Ternary Operator, Switch Statements, Arrow Functions in the JavaScript Code Playground.