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&rsquo;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 = &quot;Welcome to this Javascript Guide!&quot;; // Output becomes !ediuG tpircsavaJ siht ot emocleW var reverseEntireSentence = reverseBySeparator(string, &quot;&quot;); // Output becomes emocleW ot siht tpircsavaJ !ediuG var reverseEachWord = reverseBySeparator(reverseEntireSentence, &quot; &quot;); function reverseBySeparator(string, separator) { return string.split(separator).reverse().join(separator); }</pre> <p>&nbsp;</p> <h1>2. How to empty an array in JavaScript?</h1> <pre> var arrayList = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;f&#39;];</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&rsquo;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>