1/24
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is JavaScript and how is it different from HTML and CSS?
JavaScript is a high-level, dynamic programming language primarily used for creating interactive effects within web browsers. Unlike HTML, which structures content, and CSS, which styles it, JavaScript adds functionality and interactivity to web pages.
Or
JavaScript is a programming language that allows you to create interactive and dynamic content on web pages, while HTML structures the content and CSS styles it.
What are the primary data types in JavaScript?
The primary data types in JavaScript include Undefined, Null, Boolean, Number, String, BigInt, and Symbol. These types determine the kind of values that can be stored and manipulated in a program.
Or
The primary data types are undefined, null, boolean, number, string, symbol (since ES6), and object.
What is a variable, and how do you declare one?
A variable is a named storage location in a program that holds data which can be changed during execution. In JavaScript, you can declare a variable using the keywords var, let, or const.
OR
A variable is a named container for storing data values. You can declare one using var
, let
, or const
. For example: let name = "John";
.
What are local and global variables?
Local variables are defined within a function and are only accessible within that function, while global variables are declared outside any function and can be accessed from anywhere in the code.
OR
Local variables are declared within a function and can only be accessed there, while global variables are declared outside any function and can be accessed from anywhere in the script.
What is a JavaScript function and how do you declare one?
A JavaScript function is a block of code designed to perform a particular task, which can be executed when called. You can declare a function using the function keyword followed by a name and parentheses.
OR
A function is a reusable block of code that performs a specific task. You can declare one using the function
keyword, like this: function greet() { console.log("Hello"); }
.
How do you create an object in JavaScript?
You can create an object in JavaScript using object literals, the Object constructor, or the class syntax. An object literal is defined using curly braces with key-value pairs.
OR
An object can be created using object literals or constructors. For example: let person = { name: "John", age: 30 };
.
What is the purpose of the "this" keyword?
The "this" keyword in JavaScript refers to the context in which a function is executed, allowing access to the object that is currently invoking the function. It can vary depending on how the function is called.
OR
The "this" keyword refers to the context in which a function is called. In a method, it refers to the object that owns the method.
How does scope work in JavaScript?
Scope in JavaScript refers to the accessibility of variables and functions in different parts of your code. It defines where variables can be accessed and modified, typically categorized into global and local scope.
OR
Scope refers to the visibility of variables and functions. JavaScript has function scope and block scope (for variables declared with let
or const
).
What are closures and how are they useful?
Closures are functions that retain access to their outer scope even after the outer function has finished executing. They are useful for data encapsulation and creating private variables.
OR
A closure is a function that retains access to its lexical scope, even when executed outside that scope, which allows for data encapsulation and private variables.
What is event bubbling and capturing?
Event bubbling and capturing are two phases of event propagation in the DOM. Bubbling occurs when an event starts from the target element and bubbles up to the root, while capturing starts from the root and goes down to the target.
OR
Event bubbling is when an event starts from the target element and bubbles up to the root, while capturing is the opposite, where the event starts from the root and goes down to the target.
How can you manipulate the DOM using JavaScript?
You can manipulate the DOM using JavaScript by selecting elements, modifying their attributes, adding or removing elements, and responding to events, allowing dynamic updates to the webpage.
OR
You can manipulate the DOM using methods like document.getElementById()
, element.appendChild()
, and element.style
.
What is a promise and how does it work?
A promise is an object that represents the eventual completion or failure of an asynchronous operation and its resulting value. It allows you to write cleaner and more manageable asynchronous code by using methods like .then() and .catch() to handle results and errors.
OR
A promise is an object representing the eventual completion (or failure) of an asynchronous operation, allowing you to handle asynchronous actions more effectively.
How do you handle asynchronous operations in JavaScript?
You handle asynchronous operations in JavaScript using promises, which represent a value that may be available now, or in the future, or never. Promises allow you to attach callbacks for when the operation completes or fails.
OR
You can handle asynchronous operations using callbacks, promises, or the async/await syntax for cleaner, more readable code.
What is the difference between "==", "===", and "!="?
" checks for value equality with type coercion, "=" checks for both value and type equality, and "!=" checks for value inequality with type coercion.
OR
==
checks for equality with type coercion, ===
checks for strict equality without coercion, and !=
checks for inequality with coercion.
What are arrow functions, and how do they differ from regular functions?
Arrow functions are a concise way to write function expressions in JavaScript, characterized by their use of the =>
syntax. They differ from regular functions in that they do not have their own this
, making them particularly useful for preserving the context of this
in callbacks.
OR
Arrow functions provide a shorter syntax for functions and do not have their own this
context, inheriting it from the outer function.
What is a callback function?
A callback function is a function that is passed as an argument to another function and is executed after a certain event or operation has completed, allowing for asynchronous programming.
OR
A callback function is a function passed as an argument to another function, to be called when an event occurs or a task is completed.
How can you prevent default behavior in an event?
You can prevent default behavior in an event by using the preventDefault() method on the event object within an event handler.
OR
You can prevent default behavior using event.preventDefault()
within an event listener.
What are template literals and how do you use them?
Template literals are string literals allowing embedded expressions, defined by backticks (`). They enable multi-line strings and string interpolation using ${expression}.
OR
Template literals are string literals allowing embedded expressions, enclosed by backticks (). Example:
let message = Hello, ${name}
;``.
What is the difference between let, const, and var?
The difference between let, const, and var lies in their scope, hoisting behavior, and mutability. 'let' and 'const' are block-scoped, while 'var' is function-scoped; 'const' cannot be reassigned, whereas 'let' and 'var' can be.
OR
var
declares a function-scoped variable, let
declares a block-scoped variable, and const
declares a block-scoped variable that cannot be reassigned.
What is JSON and how do you work with it in JavaScript?
JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for humans to read and write, and easy for machines to parse and generate. In JavaScript, you can work with JSON using the JSON object, which provides methods like JSON.stringify() to convert objects to JSON strings and JSON.parse() to convert JSON strings back into JavaScript objects.
OR
JSON (JavaScript Object Notation) is a lightweight data interchange format. You can parse it using JSON.parse()
and stringify JavaScript objects using JSON.stringify()
.
How do you handle errors in JavaScript?
Error handling in JavaScript is typically done using try, catch, and finally blocks. The try block contains code that may throw an error, the catch block handles the error, and the finally block executes code after the try/catch, regardless of the outcome.
OR
You can handle errors using try...catch
statements to catch exceptions that may occur during code execution.
What are JavaScript modules, and how do you export/import them?
JavaScript modules are reusable pieces of code that can be exported from one file and imported into another. They help to organize and encapsulate code, allowing for better maintainability and avoiding global namespace pollution.
OR
JavaScript modules allow for code organization and reuse. You can export functions or variables using export
and import them using import
.
What is the purpose of the 'debugger' statement?
The 'debugger' statement in JavaScript is used to pause the execution of code and invoke the debugging functionality of the browser's developer tools. It allows developers to inspect the state of the application at that point in the code.
OR
The debugger
statement is a debugging tool that pauses code execution, allowing you to inspect variables and execution flow in the browser's developer tools.
How can you optimize performance in JavaScript applications?
Optimizing performance in JavaScript applications involves various techniques such as minimizing DOM manipulation, using asynchronous programming, optimizing loops, and reducing the size of scripts. Additionally, leveraging caching and using performance profiling tools can help identify bottlenecks.
OR
You can optimize performance by minimizing DOM access, using efficient algorithms, reducing memory consumption, and employing lazy loading techniques.
What is the use of the window
object in the browser?
The window object represents the browser's window and serves as the global object in a web page. It provides methods and properties to control the browser, access the DOM, and manage events.
OR
The window
object represents the browser window and provides properties and methods for accessing the browser's features, such as window.alert()
and window.location
.