Few important Questions in JavaScript and ES6

1. What is an Iterator?

An iterator is an object which defines a sequence and a return value upon its termination. It implements the Iterator protocol with a next() method which returns an object with two properties: value (the next value in the sequence) and done (which is true if the last value in the sequence has been consumed.

2. What is an event loop?

The Event Loop is a queue of callback functions. When an async function executes, the callback function is pushed into the queue. The JavaScript engine doesn’t start processing the event loop until the async function has finished executing the code.

3. What is call stack?

Call Stack is a data structure for JavaScript interpreters to keep track of function calls in the program. It has two major actions,

  1. Whenever you call a function for its execution, you are pushing it to the stack.
  2. Whenever the execution is completed, the function is popped out of the stack.

4. What is an error object?

An error object is a built-in error object that provides error information when an error occurs. It has two properties: name and message. For example, the below function logs error details,

4. What are the different error names from error object?

There are 6 different types of error names returned from error object,

  1. EvalError : An error has occurred in the eval() function
  2. RangeError : An error has occurred with a number “out of range”
  3. ReferenceError : An error due to an illegal reference
  4. SyntaxError : An error due to a syntax error
  5. TypeError : An error due to a type error
  6. URIError : An error due to encodeURI()

5. What are the various statements in error handling.

Below are the list of statements used in an error handling,

  1. try: This statement is used to test a block of code for errors
  2. catch: This statement is used to handle the error
  3. throw: This statement is used to create custom errors.
  4. finally: This statement is used to execute code after try and catch regardless of the result.

6. What are primitive data types

A primitive data type is data that has a primitive value (which has no properties or methods). There are 7 types of primitive data types.

  1. String
  2. number
  3. boolean
  4. null
  5. undefined
  6. bigint
  7. symbol

7. What is Hoisting?

Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution. Remember that JavaScript only hoists declarations, not initialisation. Let’s take a simple example of variable hoisting,

8. What are classes in ES6?

In ES6, JavaScript classes are primarily syntactic sugar over JavaScript’s existing prototype-based inheritance. For example, the prototype based inheritance written in function expression as below,

9. What are closures?

A closure is the combination of a function and the lexical environment within which that function was declared. i.e, It is an inner function that has access to the outer or enclosing function’s variables. The closure has three scope chains

  1. Own scope where variables defined between its curly brackets
  2. Outer function’s variables
  3. Global variables

10. Arrow functions?

The arrow functions provides a more concise syntax for writing function expressions by opting out the function and return keywords using fat arrow(⇒) notation. Let’s see how this arrow function looks like,

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahad Hossain Aiman

Ahad Hossain Aiman

2 Followers

I am Aiman. I am a web developer. I can learn anything at any time. For that, I take the help of Google. My core skill is based on JavaScript .