JAVASCRIPT Flashcards
What are the different data types in JavaScript?
8 of them : String, number, boolean, BigInt, un defined, null, symbol and object
Explain hoisting in JavaScript.
Hoisting is the default behaviour of javascript where all the variable and function declarations are moved on top.
This means that irrespective of where the variables and functions are declared, they are moved on top of the scope. The scope can be both local and global.
To avoid hoisting, you can run javascript in strict mode by using “use strict” on top of the code:
Difference between “ == “ and “ === “ operators.
Both are comparison operators.
“==” is used to compare values, “ === “ is used to compare both values and types.
What is NaN property in JavaScript?
NaN property represents the “Not-a-Number” value. It indicates a value that is not a legal number.
What is the difference between ‘undefined’ and ‘null’ in JavaScript?
undefined means a variable has been declared but has not yet been assigned a value.
null is an assignment value. It can be assigned to a variable as a representation of no value :
How would you handle errors in JavaScript?
Errors in JavaScript can be handled using try-catch blocks, where code that may throw an error is placed within the try block, and the catch block handles the error if it occurs.
How does asynchronous programming work in JavaScript? Explain callbacks or Promises.
Asynchronous programming in JavaScript allows tasks to run in the background. Callbacks and Promises are two ways to handle asynchronous code. Callbacks are functions passed as arguments and executed when the task is complete. Promises represent the eventual completion or failure of an asynchronous operation, providing a structured approach to handle it.
What is a closure in JavaScript?
- A closure is a function that has access to variables in its outer function, even after the outer function has returned.
- It is created by nesting a function inside another function and returning the inner function.
What is event delegation in JavaScript?
Event delegation is a technique in JavaScript where instead of attaching event listeners to individual elements, you attach a single event listener to a parent element. The events are then handled when they bubble up from the child elements. This approach is useful for dynamically created elements or when dealing with a large number of elements.
What are the higher order functions in JavaScript?
- Higher order functions are functions that take one or more functions as arguments or return a function as their result.
- They are a key feature of functional programming in JavaScript.
What is the difference between let, const, and var in JavaScript?
- let and const are block-scoped, while var is function-scoped.
- The value of a variable declared with const cannot be reassigned, while the value of a variable declared with let or var can.
- Variables declared with let and const are not hoisted, while variables declared with var are hoisted.
What is the difference between synchronous and asynchronous programming in JavaScript?
- Synchronous programming executes code sequentially, one line at a time.
- Asynchronous programming allows code to be executed out of order, and it usually involves the use of callbacks, promises, or async/await.
What is JavaScript?
- JavaScript is a programming language that is used to create interactive effects within web browsers.
- It is a high-level, interpreted language that is easy to learn and use.
What is the event loop in JavaScript?
- The event loop is a mechanism in JavaScript that allows for asynchronous programming.
- It continuously checks the call stack and the message queue to see if there are any tasks that need to be executed.