Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Javascript code to get URL and Its different parts through code?

Answer» JAVASCRIPT code to GET URL and Its different parts through code?
Below is the code to get different part of URL in Javascript
(1)window.location.protocol=This will return "http:" or "https:"
(2)window.location.host=This will return rest part of url LIKE "crackyourinterview.com"
(3)window.location.pathname=this will return the part after .com like "/MainAds-web.aspx"
(4)window.location.search=this will return ?s=search text
2.

Replace all in Javascript with function to replace string?

Answer»

Replace all in Javascript with function to replace STRING?
Below is the code to replace all world from the GIVEN string in javascript.
(1)Create function to replace string have 3 input PARAMETER as given in screen


JavascriptReplaceall
(2)Here we have declared a string and the calling of function


Replaceall Javascript

3.

How to know user is a mobile or desktop user with the help Javascript Code?

Answer»

How to know user is a mobile or DESKTOP user with the HELP Javascript Code?
Below is the simplest code which will check that user is a mobile or a desktop user

var INDEX = navigator.appVersion.indexOf("Mobile");
if(index>-1)
{
window.location.href = "https://crackyourinterview.com";
}

4.

Create a function without function name but having parameter in Javascript?

Answer»

Create a function WITHOUT function name but having PARAMETER in Javascript?
Below is the code of javascript to create a function without the function name but have parameter. Here we will create a variable with below GIVEN name:-

VAR biggestval= function()

But to get the output we use variable name with "(var1,var2);". And so we use biggestval(var1,var2);


DOWNLOAD Code

Functionwithout param

5.

Code to find last occurrence of any word in given sentance or string in Javascript?

Answer»

Code to FIND LAST occurrence of any word in given sentance or STRING in Javascript?
Below are the code to find the last occurrence of any word in given some particular string.


Download Code



LastIndexOf Javascript

6.

selected radiobuttonlist value in javascript

Answer» VAR objList = document.getElementById("radiobuttonid");

var RdlBoxCount = objList.getElementsByTagName("input");

for(var i = 0;i< RdlBoxCount.length;i++)

{

var RdlBoxRef = RdlBoxCount[i];

if (RdlBoxRef.checked == TRUE)

{

var labelArray = RdlBoxRef.parentNode.getElementsByTagName("label")

var val = labelArray[i].innerHTML;

alert(val)

}

}
7.

Create a Function in Javascript without function name with zero parameter?

Answer» CREATE a Function in Javascript WITHOUT function name with ZERO parameter?
Below is the code of javascript to create a function without the function name. Here we will create a variable with below given name:-

var biggestval= function()

But to get the OUTPUT we USE variable name with "();". And so we use biggestval();


Download Code

Function Without name
8.

Reverse a Array in Javscript by using reverse keyword?

Answer»

Reverse a ARRAY in Javscript by USING reverse KEYWORD?
Below is the code to reverse a array with keyword reverse. As per the code GIVEN below:-

Download Code


Array Reverse Javascript

9.

Function to disable Back Button in javascript

Answer» FUNCTION disableBackButton()
{
window.history.forward();
}
SETTIMEOUT("disableBackButton()", 0);