- Published on
Getting Started with JS, v2 by Kyle Simpson [Programming Primer]
- Authors
- Name
- Sudhakar J
Getting Started with JavaScript, v2 by Kyle Simpson
Course Materials
Programming Primer Notes
Operations
- JavaScript operators are symbols that are used to perform operations on operands.
Types
typeof
operator is used to return a string that represents the type of JavaScript for a given value.
console.log(typeof 42)
// Expected output: "number"
console.log(typeof 'blubber')
// Expected output: "string"
console.log(typeof true)
// Expected output: "boolean"
Variables
- A variable is a named reference to a
value
(Representation of some place in memory).
Expresions and Statements
- Part of a statement is an expression.
If & Else (Decisions)
if (condition) statement1
// With an else clause
if (condition) statement1
else statement2
Loops
- The statements for loops provided in JavaScript are:
- for statement
- do...while statement
- while statement
- labeled statement
- break statement
- continue statement
- for...in statement
- for...of statement
for (initialization; condition; afterthought) statement
//
for (let step = 0; step < 5; step++) {
// Runs 5 times, with values of step 0 through 4.
console.log('Walking east one step')
}
Functions
functions
are first-class objects, because they can be passed to other functions, returned from functions, and assigned to variables and properties.- They can also have properties and methods just like any other object. - What distinguishes them from other objects is that functions can be called.
function square(number) {
return number * number
}
function expression
- The
function
keyword can be used to define a function inside an expression. - The main difference between a function expression and a function declaration is the function name, which can be omitted in function expressions to create anonymous functions.
const getRectArea = function (width, height) {
return width * height
}
console.log(getRectArea(3, 4))
// Expected output: 12