100 Most Frequently Asked JavaScript Interview Questions – Part 4

  • Question 31. Can parameter objects be used for ES6 arrow functions?
  • Question 32. How can I create an object without a prototype?
  • Question 33. What is the scope of variables in JavaScript?
  • Question 34. What is the scope of this in JavaScript?
  • Question 35. What is a Callback in JavaScript?
  • Question 36. How does the typeOf operator work?
  • Question 37. Explain equality in JavaScript
  • Question 38. What is the difference between ‘==’ and ‘===’?
  • Question 39. What is ECMAScript?
  • Question 40. What are the new features in ES6 or ECMAScript 2015?
  • The related content

Question 31. Can parameter objects be used for ES6 arrow functions?

A: No, the Arguments object does not work with ES6 arrow Functions.

function one() {
   return arguments;
}
const two = function () {
   return arguments;
}
const three = function three() {
   return arguments;
}
const four = () = > arguments;
four(); // Throws an error - arguments is not defined
Copy the code

When we call the function four, it raises ReferenceError: parameter undefined error.

If your environment supports the rest of the syntax, we can resolve this issue.

const four = (. args) = > args;
Copy the code

This automatically puts all parameter values into the array.

Question 32. How can I create an object without a prototype?

A: We can use this method to create object.create method without a prototype.

const o1 = {};
console.log(o1.toString());
// logs [object Object] get this method to the Object.prototype

const o2 = Object.create(null);
// the first parameter is the prototype of the object "o2" which in this case will be null specifying we don't want any prototype
console.log(o2.toString());
// throws an error o2.toString is not a function
Copy the code

Question 33. What is the scope of variables in JavaScript?

A: The scope of a variable is the area defined in the program. JavaScript variables will have only two scopes.

  • Global variables – A global variable has global scope, which means it is visible anywhere in your JavaScript code.
  • Local variable – A local variable is visible only in the function that defines it. Function arguments are always local to the function.

Question 34. What is the scope of this in JavaScript?

This keyword in JavaScript refers to the object to which it belongs.

It has different meanings depending on where it is used.

  • In a method, this refers to the owner object
  • In functions, this refers to the global object.

Question 35. What is a Callback in JavaScript?

A:

  • Callbacks are ordinary JavaScript functions passed as arguments or options to some method.
  • This function is executed after the other function has finished executing, hence the name “callback.”
  • In JavaScript, functions are objects, so functions can take functions as arguments and can be returned by other functions.

Question 36. How does the typeOf operator work?

A:

  • thetypeofThe data type used to get its operand.
  • Operands can be literal or data structures, such as variables, functions, or objects.
  • It is a unary operator that precedes its single operand, which can be of any type.
  • Its value is a string indicating the data type of the operand.

Question 37. Explain equality in JavaScript

A: JavaScript has a strict comparison with type conversions:

  • Rigorous comparison(e.g.= = =) checks whether values are equal without forcing it
  • Abstract compared(e.g.= =) checks whether values are equal if coercion is allowed.
var a = "42";
var b = 42;
a == b; // true
a === b; // false
Copy the code

Some simple rules of equality:

– If any of the values (aka “positive” values) in the comparison can be true or false, do not use ==, use === instead.

  • If any of the values in the comparison can be these specific values (0, “”, or [] -empty array), do not use it= =, while the use of= = =.
  • In all other cases, you can use it safely= =. Not only is it secure, but in many cases it simplifies code in ways that improve readability.

Question 38.= =and= = =What’s the difference?

== is the abstract equality operator, while === is the strict equality operator. After == has done any necessary type conversions, the operator will compare for equality. The === does no type conversion, so if two values are of different types === will simply return false. Some interesting things can happen when using ==, such as:

1= ="1"; // true
1= = [1]; // true
1= =true; // true
0= =""; // true
0= ="0"; // true
0= =false; // true
Copy the code

Question 39. What is ECMAScript?

  • ECMAScript is the standard for making scripting languages, which means that JavaScript follows specification changes in the ECMAScript standard because it is the blueprint for JavaScript.
  • ECMAScript is standardized by the ECMA International Standards Organization in the ECMA-262 and ECMA-402 specifications.

Read more about ECMAScript here.

Question 40. What are the new features in ES6 or ECMAScript 2015?

  • Arrow Functions
  • Classes
  • Template Strings
  • Enhanced Object literals
  • Object Destructuring
  • Promises
  • Generators
  • Modules
  • Symbol
  • Proxies
  • Sets
  • Default Function parameters
  • Rest and Spread Operators
  • Block Scoping with let and const

Thank you for reading this blog post and I hope it was helpful. I’ll be updating part 5-10 of this series soon, it should be tomorrow, and I’ll keep Posting at least one post a day, follow me, or ❤ or 📑 bookmark this post and I’ll put a link to it at the end of this post.

Save or long press to identify the author of the public accountWhat do you want biu to order



I will continue to update similar free fun H5 games, Java games, front-end basic knowledge, fun, practical projects and software, and so on

And finally, don’t forget ❤ or 📑

The related content

100 Most Frequently Asked JavaScript Interview Questions – Part 1 (1-10) 100 Most Frequently Asked JavaScript Interview Questions – Part 2 (11-20) 100 Most Frequently Asked JavaScript Interview Questions – Part 1 (21-30)