JavaScript Tricky Interview Questions

JavaScript Tricky Interview Questions
Download JavaScript Tricky Interview Questions PDF

Below are the list of Best JavaScript Tricky Interview Questions and Answers

Type coercion is the process of converting value from one type to another (such as string to number, object to boolean, and so on)

By using Number.isInteger() function

str.trim() method is used to remove the white spaces from both the ends of the given string.



Return value: This method returns a new string, without any of the leading or the trailing white spaces.

You can use the following code to strip whitespaces from String in JavaScript:

<!DOCTYPE html> 





        How to remove spaces from 

        a string using JavaScript? 





    <h1 style="color: green"> 

        Online Interview Questions 




        How to remove spaces from 

        a string using JavaScript? 




        Original string is:  

        Online Interviews Questions 




        New String is:  

        <span class="output"></span> 



    <button onclick="removeSpaces()"> 

        Remove Spaces 



    <script type="text/javascript"> 

        function removeSpaces() { 

            originalText =  

                "Online Interviews Questions"; 


            newText =  

                originalText.replace(/ /g, ""); 



                    = newText; 







Strip Whitespaces