Top 10 tricky JavaScript questions that I used to ask in interviews
<p>Some tricky interview scheduling questions you will face. These questions seem easy, but there is something fishy about them. So today I’m going to show you 10 tricky questions to ask yourself before a programmer interview.</p>
<h1>1. Given a string, reverse each word in the sentence</h1>
<pre>
var string = "Welcome to this Javascript Guide!";
// Output becomes !ediuG tpircsavaJ siht ot emocleW
var reverseEntireSentence = reverseBySeparator(string, "");
// Output becomes emocleW ot siht tpircsavaJ !ediuG
var reverseEachWord = reverseBySeparator(reverseEntireSentence, " ");
function reverseBySeparator(string, separator) {
return string.split(separator).reverse().join(separator);
}</pre>
<p> </p>
<h1>2. How to empty an array in JavaScript?</h1>
<pre>
var arrayList = ['a', 'b', 'c', 'd', 'e', 'f'];</pre>
<p><strong>Method 1</strong></p>
<pre>
arrayList = [];</pre>
<p>The above code sets the arrayList variable to a new empty array. This is recommended if you don’t have references to the original ArrayList elsewhere, as it actually creates a new empty array.</p>
<p><strong>Method 2</strong></p>
<pre>
arrayList.length = 0;</pre>
<p>The code above clears the existing array by setting its length to 0. This way of emptying the array also updates all reference variables that point to the original array.</p>
<p><a href="https://emma-delaney.medium.com/top-10-tricky-javascript-questions-that-i-used-to-ask-in-interviews-2cb3912271a9">Read More</a></p>