Tricky Questions of JavaScript

PRa Tik Dev
3 min readMay 9, 2021

1.What is Reverse String:

Reverse String means inverted string. Suppose you have a string and you want this string will start from the last word to the first word. For your doubt, there is an example below :

const myString = "Hi, I'm Javascript"
function ReverseString(restr){
let newString= ""
for(let i=0; i<restr.lenght; i++)
let everyWord = restr[i];
newString = everyWord + newString;
}
return newString;
}
let reverseString = ReverseString(myString);

2.What is the difference between Null Vs Undefined:

Null is a value that indicates a deliberate non-value and Undefined means that it is an uninitialized variable that hasn’t even been assigned yet.

3. Describe the ‘This’ keyword:

This keyword is used depending on where it is used. In a method section, it is used as the owner object. In a function section, it is used as a global object but if this function section refers to strict mode, its value is undefined. In an event, it refers to the element that received the event.

4.How Javascript works event loop stack and queue:

when we call a function in javascript, there is an event loop and the called functions make a stack together. All called functions stay as a frame in the stack step by step. Then, Javascript executes the frames. After executing all frame then it comes to the queue. It is the process of event loop stack and queue.

5. How to find the largest element of an array?

Solution:

const array = [88, 99, 77, 66, 44, 33, 22, 11]const largeValue = array[0]for(let i=0; i<array.length; i++){
let perValue = array[i];
if(perValue > largeValue){
largeValue = perValue;
}
}

6. What is ‘Event bubble’ :

When an event happens on an element, the handlers run in first and after that run the parent of this element then all the way up on other. It is the principle of event bubble.

7. What is an API and what is the purpose of API:

API(Application Programming Interface) is software that two application to talk to each other. It helps to frontend side of a website to receive data from the backend. Suppose, you have some data for your website and you store those data on a backend server but now you need those data to show on the frontend and then you need API to call those data. Now can understand that API makes a relation between frontend and backend.

8.What is DOM:

DOM(Document Object Model) is an interface of HTML that we write in the editor and the website shows our coding result on web pages. Basically, Dom helps to show the result. The DOM is an object-oriented representation of the web page.

9. Check whether a number is a Prime Number or not:

Solution:

let number = 786
for(i=2; i<number-1 ; i++){
if(n%i == 0){
console.log("It is not a prime number")
break;
}
}

10.Count the number of words in a string:

Solution:

const string = ‘ Hi! This is Javascript. I’m a high-level, lightweight, often just- in-time compiled, and multi-paradigm language’.let count = 0;for(let i=0; i< string.length; i++){let singleChar = string[i]if(singleChar == “ ” && string[i-1] != “ ”){count++}}count++;

--

--