Important JS Interview Questions Part 2
how to find palindrome in javascript?
Palindrome: a word, phrase, or sequence that reads the same backwards as forwards, e.g. madam or nurses run.
function palindrome(str) {
const reversed = str
.split('')
.reverse()
.join('');
return str === reversed;
}Write some of the features of ES6 in JS.
- Support for constants.
- Block-Scope support for both variables, constants, functions.
- Arrow functions.
- Extended Parameter Handling.
- Template Literals and Extended Literals.
- Destructuring.
- Modules, Classes, Iterators, Generators.
- Enhanced Regular Expression.
- Enhanced Object Properties.
- Promises, Meta-Programming ,Internationalization and Localization.
Arrow Function
Arrows is a new syntax for functions, which brings several benefits: Arrow syntax automatically binds this to the surrounding code’s context. The syntax allows an implicit return when there is no body block, resulting in shorter and simpler code in some cases.
What is Set?
Set objects are collections of unique values. Duplicate values are ignored, as the collection must have all unique values. The values can be primitive types or object references. Also, NaN and undefined can also be stored in a Set
What is Generator function?
Generator functions are a new feature in ES6 that allows a function to generate many values over time by returning an object which can be iterated over to pull values from the function one value at a time.
Get BH Nibir’s stories in your inbox
Join Medium for free to get updates from this writer.
A generator function returns an iterable object when it’s called. It is written using the new * syntax as well as the new yield keyword introduced in ES6.
What is WeakMap in ES6?
The WeakMap is same as Map where it is a collection of key/value pairs. But in WeakMap, the keys must be objects and the values can be arbitrary values. The object references in the keys are held weakly, meaning that they are a target of garbage collection (GC) if there is no other reference to the object anymore. The WeakMap API is the same as the Map API.
What is Class expression?
The Class expression is one way to define a class in ES6. Similar to function expressions, class expressions can be named or unnamed. If named, the name of the class is local to the class body only. JavaScript classes use prototype-based inheritance.
What will be the output of this code?
var x = 10;
var age= function () {
console.log(x);
var x = 20;
};
age();Ans: undefined
It’s because JavaScript initialization is not hoisted. The reason is that when the function is executed, it checks that there’s a local x variable present but doesn’t yet declare it, so it won’t look for a global one.






