15 Common JavaScript Interview Questions Asked at Proficed
In this blog post, we will discuss 15 common JavaScript interview questions asked at Proficed for roles like “Website Designer” and “Frontend Developer.” These questions aim to assess your core knowledge and your ability to apply JavaScript techniques in practical scenarios.
[1] What is the difference between an Array and a Set in JavaScript?
Answer: An Array allows duplicate values, while a Set only stores unique values. Arrays maintain insertion order and use numeric indices, while Sets do not allow duplicate elements and do not provide direct indexing.
[2] Using which for
loop can I iterate through all properties of an array and using which for
loop can I iterate through all elements of an array?
Answer:
- To iterate through all properties of an array (including non-index properties), use a
for...in
loop. - To iterate through all elements of an array, use a
for...of
loop or a traditionalfor
loop.
[3] Name any 5 array functions in JavaScript.
Answer: Some common array functions are:
push()
pop()
slice()
map()
filter()
[4] How to check if an input element contains valid data using JavaScript?
Answer: Use the checkValidity()
method of the input element to check if the input value is valid based on HTML5 validation rules.
[5] How to parse a string to a number in JavaScript?
Answer: You can use parseInt()
, parseFloat()
, or the unary +
operator to parse a string into a number.
[6] Is there any difference between adding JavaScript before closing </head>
and before closing </body>
tag?
Answer: Yes. JavaScript added before </head>
is parsed and executed before the page content is fully loaded, which may block rendering. Placing JavaScript before </body>
ensures the DOM is fully loaded before the script runs, leading to better performance.
[7] Which string function can be used to extract a part of a string and return the extracted part in a new string?
Answer: The slice()
method can be used to extract part of a string and return it as a new string.
[8] Which two functions can be used as alternatives to slice()
in JavaScript to get the same result?
Answer: The two alternatives to slice()
are substring()
and substr()
(though substr()
is considered deprecated).
[9] Which function is common between string objects and array objects in JavaScript?
Answer: The slice()
function is common between both string and array objects.
[10] What should I do if I want to count the position from the end in the reverse direction in the slice
function (e.g., to extract the last 5 characters of a string)?
Answer: Use negative indices in the slice()
method. For example, to extract the last 5 characters: str.slice(-5)
.
[11] What does the splice()
method do? What is the recently introduced alternative method of it?
Answer: The splice()
method adds, removes, or replaces elements in an array, modifying the original array. The recently introduced alternative is the toSpliced()
method, which returns a new array with the modifications, leaving the original array unchanged.
[12] Which is the one method common for all JavaScript objects?
Answer: The toString()
method is common for all JavaScript objects.
[13] What will [1, 2, 3].map(alert)
this line do?
Answer: It will alert each element of the array individually (i.e., 1, 2, and 3), as map()
executes the callback function (in this case, alert
) on every element of the array.
[14] Which method can I use to convert a multi-dimensional array into a one-dimensional array?
Answer: You can use the flat()
method to convert a multi-dimensional array into a one-dimensional array.
[15] How are the delete()
, pop()
, and shift()
methods in an array different?
Answer:
delete()
removes the element but does not change the array length or reindex the array.pop()
removes the last element of the array and reduces the length by one.shift()
removes the first element of the array and reindexes the remaining elements.
These questions span a wide range of JavaScript knowledge, from basic syntax to practical usage of array and string methods. Preparing for them will boost candidates' confidence during interviews for positions like “Website Designer” and “Frontend Developer” at Proficed.
Member discussion