20 Sample Exam/Interview Questions for Javascript

Here are 20 sample exam/interview questions and answers for JavaScript for bachelor studies:

  1. What is the difference between let and var in JavaScript?
  • let is a block-scoped variable and var is a function-scoped variable.
  1. What is the difference between == and === in JavaScript?
  • == compares values for equality and === compares values and data types for equality.
  1. How do you define a function in JavaScript?
  • Functions can

    be defined using the function keyword or using arrow notation.
  1. What is an object in JavaScript?
  • An object in JavaScript is a collection of key-value pairs.
  1. What is the difference between null and undefined in JavaScript?
  • null is a value that represents no value, while undefined means that a variable has been declared but has not been assigned a value.
  1. What is the difference between == and === in JavaScript?
  • == compares values for equality and === compares values and data types for equality.
  1. What is the difference between == and === in JavaScript?
  • == compares values for equality and === compares values and data types for equality.
  1. How do you create an array in JavaScript?
Arrays can be created using the [] notation or the Array() constructor.
  1. How do you loop through an array in JavaScript?
Arrays can be looped through using a for loop, forEach() method, map() method or for...of loop
  1. How do you create an object in JavaScript?
Objects can be created using object literal notation or object constructor.
  1. How do you access properties of an object in JavaScript?
Properties can be accessed using the dot notation or bracket notation.
  1. What is the difference between a while loop and a do-while loop in JavaScript?
  • A while loop checks the condition before executing the loop, while a do-while loop executes the loop first and then checks the condition.
  1. What is the purpose of the break statement in JavaScript?
  • The break statement is used to exit a loop or a switch statement.
  1. What is the difference between the continue and break statements in JavaScript?
  • The continue statement is used to skip the current iteration of a loop, while the break statement is used to exit a loop or a switch statement.
  1. What is the difference between a local variable and a global variable in JavaScript?
  • A local variable is defined within a function and is only accessible within that function, while a global variable is defined outside of any function and is accessible throughout the entire program.
  1. What is a closure in JavaScript?
  • A closure is a function that has access to the variables in its parent scope, even after the parent function has completed execution.
  1. What is a promise in JavaScript?
  • A promise is an object that represents the eventual completion of an asynchronous operation.
  1. What is an event in JavaScript?
  • An event in JavaScript is an action or occurrence that can be detected by the program.
  1. What is the difference between callbacks and promises in JavaScript?
  • Callbacks are a way to handle async operations by passing a function as an argument, while Promises provide a more powerful and flexible way to handle async operations.
  1. What is the difference between == and === in javascript
  • == compares values for equality and === compares values and data types for equality.

Please keep in mind that these questions and answers are just a sample and are not exhaustive. Additionally, I suggest double-checking the answers and also checking the latest JavaScript standards and best practices as the field is constantly evolving.

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.