10 Questions
What is JavaScript primarily used for?
Client-side scripting on the web
What is the data type of the variable x
in the code let x = 42
?
Number
Which operator is used to assign a value to a variable?
=
What is the purpose of an if-else
statement?
To make a decision based on a condition
What is the difference between let
and const
?
let
is used for variables, const
is used for constants
What is the syntax to create a function using a function declaration?
function add(x, y) { return x + y; }
How do you access properties in an object using bracket notation?
obj['name']
What is the purpose of the Document Object Model (DOM)?
To interact with and manipulate web pages
What triggers an event in JavaScript?
User interactions
How do you call a function in JavaScript?
Using the function name followed by parentheses
Study Notes
JavaScript Basics
- JavaScript is a high-level, dynamic, and interpreted programming language.
- It's primarily used for client-side scripting on the web, but can also be used for server-side programming, desktop and mobile app development, and game development.
- JavaScript is often used to add interactive elements to websites, create web applications, and manipulate web pages.
Data Types
-
Primitive types:
- Number (e.g., 42)
- String (e.g., "hello")
- Boolean (e.g., true or false)
- Null (e.g., null)
- Undefined (e.g., undefined)
-
Complex types:
- Object (e.g., {name: "John", age: 30})
- Array (e.g., [1, 2, 3, 4, 5])
Variables and Operators
-
Variables:
- Declare using
let
,const
, orvar
- Assign values using the assignment operator (=)
- Declare using
-
Operators:
- Arithmetic operators (e.g., +, -, *, /, %)
- Comparison operators (e.g., ==, !=, ===, !==)
- Logical operators (e.g., &&, ||, !)
- Assignment operators (e.g., +=, -=, *=, /=)
Control Structures
-
Conditional statements:
- If statements (e.g.,
if (x > 5) { ... }
) - If-else statements (e.g.,
if (x > 5) { ... } else { ... }
) - Switch statements (e.g.,
switch (x) { case 1: ...; break; case 2: ...; break; ... }
)
- If statements (e.g.,
-
Loops:
- For loops (e.g.,
for (let i = 0; i < 5; i++) { ... }
) - While loops (e.g.,
while (x > 5) { ... }
) - Do-while loops (e.g.,
do { ... } while (x > 5)
)
- For loops (e.g.,
Functions
-
Defining functions:
- Function declaration (e.g.,
function add(x, y) { return x + y; }
) - Function expression (e.g.,
const add = function(x, y) { return x + y; };
)
- Function declaration (e.g.,
-
Function calls:
- Call a function by using its name followed by parentheses containing arguments (e.g.,
add(2, 3)
)
- Call a function by using its name followed by parentheses containing arguments (e.g.,
Objects and Arrays
-
Objects:
- Create using object literals (e.g.,
{name: "John", age: 30}
) - Access properties using dot notation (e.g.,
obj.name
) or bracket notation (e.g.,obj["name"]
)
- Create using object literals (e.g.,
-
Arrays:
- Create using array literals (e.g.,
[1, 2, 3, 4, 5]
) - Access elements using index notation (e.g.,
arr[0]
)
- Create using array literals (e.g.,
DOM and Events
-
Document Object Model (DOM):
- A programming interface for HTML and XML documents
- Allows JavaScript to interact with and manipulate web pages
-
Events:
- Triggered by user interactions (e.g., clicks, hover, scroll)
- Handled using event listeners (e.g.,
addEventListener
)
JavaScript Basics
- JavaScript is a high-level, dynamic, and interpreted programming language.
- It's primarily used for client-side scripting on the web, but can also be used for server-side programming, desktop and mobile app development, and game development.
- JavaScript is often used to add interactive elements to websites, create web applications, and manipulate web pages.
Data Types
- Primitive types include Number, String, Boolean, Null, and Undefined.
- Complex types include Objects and Arrays.
- Examples of primitive types: Number (e.g., 42), String (e.g., "hello"), Boolean (e.g., true or false), Null (e.g., null), and Undefined (e.g., undefined).
- Examples of complex types: Object (e.g., {name: "John", age: 30}) and Array (e.g., [1, 2, 3, 4, 5]).
Variables and Operators
- Variables are declared using let, const, or var and assigned values using the assignment operator (=).
- Arithmetic operators include +, -, *, /, and %.
- Comparison operators include ==, !=, ===, and !==.
- Logical operators include &&, ||, and !.
- Assignment operators include +=, -=, *=, /=.
Control Structures
- Conditional statements include If, If-else, and Switch statements.
- If statements are used to execute a block of code if a condition is true (e.g., if (x > 5) {...}).
- If-else statements are used to execute a block of code if a condition is true and another block of code if the condition is false (e.g., if (x > 5) {...} else {...}).
- Switch statements are used to execute a block of code based on the value of an expression (e.g., switch (x) { case 1:...; break; case 2:...; break;...}).
- Loops include For, While, and Do-while loops.
- For loops are used to execute a block of code for a specified number of iterations (e.g., for (let i = 0; i < 5; i++) {...}).
- While loops are used to execute a block of code while a condition is true (e.g., while (x > 5) {...}).
- Do-while loops are used to execute a block of code at least once and then continue to execute it while a condition is true (e.g., do {...} while (x > 5)).
Functions
- Functions can be defined using function declarations or function expressions.
- Function declarations are used to define a function (e.g., function add(x, y) { return x + y; }).
- Function expressions are used to define a function and assign it to a variable (e.g., const add = function(x, y) { return x + y; };).
- Functions can be called by using their name followed by parentheses containing arguments (e.g., add(2, 3)).
Objects and Arrays
- Objects are created using object literals (e.g., {name: "John", age: 30}).
- Properties can be accessed using dot notation (e.g., obj.name) or bracket notation (e.g., obj["name"]).
- Arrays are created using array literals (e.g., [1, 2, 3, 4, 5]).
- Elements can be accessed using index notation (e.g., arr[0]).
DOM and Events
- The Document Object Model (DOM) is a programming interface for HTML and XML documents.
- The DOM allows JavaScript to interact with and manipulate web pages.
- Events are triggered by user interactions (e.g., clicks, hover, scroll).
- Events are handled using event listeners (e.g., addEventListener).
Learn the fundamentals of JavaScript, a high-level programming language used for client-side scripting, server-side programming, and more.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free