Few important Questions in JavaScript and ES6

Short Introduction

1. What is an Iterator?

Example: Use ES6 class,

2. What is an event loop?

Note: It allows Node.js to perform non-blocking I/O operations even though JavaScript is single-threaded.

3. What is call stack?

  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.

Let’s take an example, and it’s a state representation in a diagram format

4. What is an error object?

4. What are the different error names 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.

  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

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

7. What is Hoisting?

The above code looks like as below to the interpreter,

8. What are classes in ES6?

Whereas ES6 classes can be defined as an alternative

9. What are closures?

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

Let’s take an example of the closure concept,

As per the above code, the inner function(i.e, greetingInfo) has access to the variables in the outer function scope(i.e, Welcome) even after the outer function has returned.

10. Arrow functions?

You can also skip parenthesis(()) if the function has exactly one parameter(either zero or more than one parameter). Apart from this, you can wrap braces({}) if the function has more than one expression in the body.

Let’s list down all the variations of arrow functions,

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 .