Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdestafadilah/12d43e45bdc6c6515eb28007361c4e53 to your computer and use it in GitHub Desktop.
Save mdestafadilah/12d43e45bdc6c6515eb28007361c4e53 to your computer and use it in GitHub Desktop.
Top 10 Interview Questions with Coding Examples 2023
What is closure in JavaScript and how does it work?
Answer: Closure is a feature in JavaScript where a function has access to its outer scope even after the outer function has returned. It is created when a function is defined inside another function, and the inner function retains access to the variables in the outer function's scope.
Can you explain hoisting in JavaScript?
Answer: Hoisting is a behavior in JavaScript where variable and function declarations are moved to the top of their scope, regardless of where they are declared in the code. This means that variables and functions can be called before they are declared, but the value of variables will be undefined until they are assigned a value.
What is the difference between == and === in JavaScript?
Answer: The double equals (==) performs type coercion, which means it converts the data type of one operand to match the data type of the other operand before making a comparison. The triple equals (===) does not perform type coercion and only returns true if both operands have the same data type and value.
How do you declare a variable in JavaScript?
Answer: Variables in JavaScript can be declared using the "var", "let" or "const" keywords. The "var" keyword is used to declare a variable with function scope, while "let" and "const" are used to declare variables with block scope.
Can you explain the event loop in JavaScript?
Answer: The event loop in JavaScript is a mechanism that allows the execution of code to be scheduled in a non-blocking way. The event loop continuously checks the message queue for new messages, and if there is a message, it executes the corresponding callback function. This allows the JavaScript engine to handle multiple events and execute code in a responsive and efficient manner.
What is the difference between null and undefined in JavaScript?
Answer: Undefined means a variable has been declared but has not been assigned a value, while null is a value assigned to a variable that represents no value or no object.
What is a JavaScript callback function?
Answer: A callback function is a function passed as an argument to another function, which is then executed at a later time. Callback functions are commonly used in JavaScript to handle asynchronous operations, such as making a network request or setTimeout().
How do you declare a function in JavaScript?
Answer: Functions in JavaScript can be declared using the "function" keyword followed by the function name, its parameters in parentheses, and its code block in curly braces. Functions can also be declared using function expressions and arrow functions.
What is the difference between let and var in JavaScript?
Answer: The "let" and "var" keywords are used to declare variables in JavaScript, but they have different scoping rules. Variables declared with "var" have function scope, which means they can be accessed within the entire function, while "let" variables have block scope, which means they can only be accessed within the block they are declared in.
Can you explain the "this" keyword in JavaScript?
Answer: The "this" keyword in JavaScript refers to the object that the function is a method of. Its value depends on how the function is called, and it can be set using bind, call or apply methods. If a function is not a method of an object, "this" refers to the global object (window in the browser).
source: https://www.udemy.com/course/javascript-dom-dynamic-web-interactive-content-boot-camp/learn/lecture/3359716#announcements/7592400/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment