Podcast
Questions and Answers
Flashcards are hidden until you start studying
Study Notes
Variables
- In JavaScript, a variable is a container that holds a value.
- Variables are declared using the
let
,const
, orvar
keywords. let
andconst
are block-scoped, whilevar
is function-scoped.const
variables cannot be reassigned, whilelet
andvar
variables can be reassigned.
Data Types
- Primitive Data Types:
- Number (e.g., 1, 3.14)
- String (e.g., "hello", 'hello')
- Boolean (e.g., true, false)
- Null (e.g., null)
- Undefined (e.g., undefined)
- Complex Data Types:
- Array (e.g., [1, 2, 3])
- Object (e.g., {name: "John", age: 30})
Functions
- A function is a block of code that can be executed multiple times from different parts of a program.
- Functions can take arguments, which are values passed to the function when it is called.
- Functions can return values, which can be used by the calling code.
- Functions can be declared using the
function
keyword or as an arrow function (e.g.,() => { ... }
).
Conditional Statements
- If Statement:
- Used to execute a block of code if a condition is true.
- Syntax:
if (condition) { code to execute }
- If-Else Statement:
- Used to execute a block of code if a condition is true, and another block of code if the condition is false.
- Syntax:
if (condition) { code to execute } else { code to execute }
- Switch Statement:
- Used to execute a block of code based on the value of an expression.
- Syntax:
switch (expression) { case value: code to execute; break; ... }
Loops
- For Loop:
- Used to execute a block of code repeatedly for a specified number of iterations.
- Syntax:
for (initialization; condition; increment) { code to execute }
- While Loop:
- Used to execute a block of code repeatedly while a condition is true.
- Syntax:
while (condition) { code to execute }
- Do-While Loop:
- Used to execute a block of code repeatedly while a condition is true.
- Syntax:
do { code to execute } while (condition)
- For-Of Loop:
- Used to execute a block of code for each item in an iterable (e.g., array, string).
- Syntax:
for (variable of iterable) { code to execute }
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.