JavaScript Interview Questions and Answers for Freshers

JavaScript Interview Questions and Answers for Freshers

Arun R's photo
Arun R
·Oct 14, 2022·

3 min read

Subscribe to our newsletter and never miss any upcoming articles

JavaScript is one of the most important skills that are in demand in Tech industry. JavaScript has proven its capabilities and Top giants like Google and Facebook are using JavaScript, According to the LinkedIn emerging reports for 2022. 60 % of Tech jobs require JavaScript, Here in this article we are going to see about some of the top 7 JavaScript Interview Questions and Answers for Freshers.

  1. What is the difference between var, let, and const?

JavaScript has three different keywords to declare a variable, The differences between the three are based on scope, hoisting, and reassignment.

difference between var, let, and const.jpg

2. Write a note on the split method ?

JavaScript has a method for splitting a string by a character and creating a new array out of the sections. We will use the split() method to separate the array by a whitespace character, represented by " ".

Example:

const originalString = "Hey happy weekend";

const splitString = originalString.split(" ");

console.log(splitString);

Output :

[ 'Hey', 'happy', 'weekend' ]

3. How to trim strings?

The JavaScript trim() method removes white space from two ends of a string, but not anywhere in the middle. Whitespace can be tabs or spaces.

Example:

const tooMuchWhitespace = " Hey happy weekend ";

const trimmed = tooMuchWhitespace.trim();

console.log(trimmed);

Output :

Hey happy weekend

4. Difference between “ == “ and “ === “ operators?

== is a comparison operator, The == operator will compare for equality after doing any necessary type conversions.

=== is a strict equality comparison operator, === will not do the conversion, so if two values are not the same type, It will return false.

5. What are Arrow functions?

We define functions using the function keyword. The concise method of defining a function known as arrow function expressions as of ECMAScript 6. Arrow functions, as they are commonly known, are represented by an equals sign followed by a greater than a sign: =>.

Arrow functions are always anonymous functions and a type of function expression.

Example :

const multiply = (x, y) => { return x * y; }

multiply(20, 4);

Output :

80

6. How does array forEach method work?

The forEach() method executes a provided function once for each array element. forEach() executes the provided callback once for each element present in the array in ascending order. It is not invoked for index properties that have been deleted or are uninitialized.

Examples

Converting a for loop to forEach

before

const items = ['item1', 'item2', 'item3'];

for (let i=0; i<items.length; i++) { console.log(items[i]); }

after

const items = ['item1', 'item2', 'item3'];

items.forEach(function(item){ console.log(item); });

7. What are the methods to extract a part of a string?

slice() : slice() method is used to extract a part of a string on the basis of its two parameters.

substr() : substr() method is the same as the slice() but it can extract a part of a string on the basis of its two parameters as the first parameter is declared for the start position and the second parameter is declared for length.

substring() : substring() method is the same as slice() but It can’t accept negative parameters.

Conclusion:

The above is the commonly asked JavaScript Interview Questions and Answers for Freshers. In the Upcoming days, we will also add more Interview Questions and Answers to this blog that are prevalent in the Industry.

Also read our new article: https://blog.skillsafari.in/full-stack-development-develop-your-pathway-in-2022

Did you find this article valuable?

Support Skill Safari by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
 
Share this