Expert JavaScript Developer

  Home  Client Side Scripting  Expert JavaScript Developer


“Expert JavaScript Developer Frequently Asked Questions in various Expert JavaScript Developer job Interviews by interviewer. The set of questions here ensures that you offer a perfect answer posed to you. So get preparation for your new job hunting”



208 Expert JavaScript Developer Questions And Answers

121⟩ How do I retrieve a cookie with a given name using a regular expression?

You can use readCookie() function to read the cookie. It provides sufficient arguments that one can find it, flexible to use. It takes cookieName as a parameter and other statements in the block. Below function uses the cookie function as well as regular expression to show the functionality:

function readCookie(cookieName)

{ var rx = new RegExp('[; ]'+cookieName+'=([^s;]*)');

var sMatch = (' '+document.cookie).match(rx);

if (cookieName && sMatch) return unescape(sMatch[1]);

return '';

}

 231 views

122⟩ Write a program to exaplain the deferred scripts using event handlers in JavaScript?

Event handler allows a trigger to be generated when a user action takes place like clicking a button, clicking on images, etc. OnLoad is an event handlers that handles all of the page's components that includes images, Java applets, and embedded multimedia to laod it in browser. The event handlers are mostly used in <BODY> tag. Event handler is also used to run several internal script statements such that it is better to use statements in a function definition and event handler invoking the function. The code below shows onLoad event handler triggers the done() function. The function consists of an alert box that gets displayed.

<HTML>

<HEAD>

<TITLE>Event_handler</TITLE>

<SCRIPT LANGUAGE="Text/JavaScript">

<!--

function done()

{

alert("The page has finished loading.")

}

// -->

</SCRIPT>

</HEAD>

<BODY Event_handler="done()">

</BODY>

</HTML>

 252 views

123⟩ How do I write script-generated content to another window?

You can use the methods winRef.document.writeln() or winRef.document.write() to write the script-generated content to another window. winRef stands for windows reference, it is being returned by window.open() method. Use of winRef.document.close() can be used if you want your script's output to show up. Example code:

writeConsole('Hello world!');

function writeConsole(content) {

top.consoleRef=window.open('','myconsole', 'width=350,height=250'

+',menubar=0')

top.consoleRef.document.writeln( '<html><head><title>Console</title></head>' +' top.consoleRef.document.close() }

 236 views

124⟩ Is it possible to break JavaScript Code into several lines?

Breaking within a string statement can be done by the use of a backslash, '', at the end of the first line

Example:

document.write("This is a program");

And if you change to a new line when not within a string statement, then javaScript ignores break in line.

Example:

var x=1, y=2,

z=

x+y;

The above code is perfectly fine, though not advisable as it hampers debugging.

 235 views

127⟩ How are tag positions used in JavaScript?

► The tag can be inserted in a document wherever there is a requirement for a tag to be put. Nested tags are also possible within a <HEAD>...</HEAD> tag. There are many other ways to use the tag like inside <BODY>...</BODY> section.

► The tags can be placed inside <SCRIPT> tag also. The position of a particular tag is not fixed and it can be placed anywhere in the HTML document. Head is a used to place the tags that consists of noncontent settings.

► The example will show the position of <SCRIPT> tag :

<HTML>

<HEAD>

<TITLE>Tag position</TITLE>

<SCRIPT LANGUAGE="Text/JavaScript">

// your script statement(s) here

</SCRIPT>

</HEAD>

<BODY>

</BODY>

</HTML>

► This uses the <SCRIPT> tag inside the HEAD section.

► There is one more code that will show the positon of <SCRIPT> in body section and it is as :

<HTML>

<HEAD>

<TITLE>Tag position</TITLE>

</HEAD>

<BODY>

<SCRIPT LANGUAGE="Text/JavaScript">

// your script statement(s) here

</SCRIPT>

</BODY>

</HTML>

 225 views

128⟩ What is variable typing?

Variable typing is used to assign a number to a variable and then assign string to the same variable. Example is as follows:

i= 8;

i="Muhammad";

 227 views

129⟩ Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any?

Timers are used to execute a piece of code at a set time or also to repeat the code in a given interval of time. This is done by using the functions setTimeout, setInterval and clearInterval.

The setTimeout(function, delay) function is used to start a timer that calls a particular function after the mentioned delay. The setInterval(function, delay) function is used to repeatedly execute the given function in the mentioned delay and only halts when cancelled. The clearInterval(id) function instructs the timer to stop.

Timers are operated within a single thread, and thus events might queue up, waiting to be executed.

 261 views

130⟩ How are event handlers utilized in JavaScript?

Events are the actions that result from activities, such as clicking a link or filling a form, by the user. An event handler is required to manage proper execution of all these events. Event handlers are an extra attribute of the object. This attribute includes event's name and the action taken if the event takes place.

 239 views

131⟩ What is Pop() method in JavaScript?

► The pop() method is similar as the shift() method but the difference is that Shift method works at the end of the array.

► The pop() method take the last element off of the given array and returns it. The array on which is called is then altered.

► For example :

var fruits = ["apple ", "banana ", "mango"];

console.log(fruits.pop() );

console.log(fruits);

► We get the following console output :

mango

["apple ", "banana "];

 247 views

132⟩ What are the requirements of Web application using JavaScript?

There are lots of application that require certain things when the user uses a JavaScript like:

Data entry validation : This tell that if the field of the form is filled out then during the processing of the server the client side can interact with it.

Serverless CGIs : This describes the processes that are not used with JavaScript but programmed as CGI on server, it gives low performace due to more interaction between the applicatioin and the user.

Dynamic HTML interactivity : It allows dynamic position of the data without using any other scripting language.

CGI prototyping : It allows more reduction of time to access the user interface before implementing the application of the CGI.

 229 views

133⟩ How to create an array in JavaScript?

► We can create an array in JavaScript as following ways :

► For example :

<script>

var fruits = new Array[];

fruits[0] = "Apple";

fruits[1] = "Orange";

fruits[2] = "Banana";

alert(fruits[1]);

</script>

► It will give output : Orange

► Another easier way to create an array is as follow :

<script>

var fruits = ["Apple","Orange","Banana"];

alert(fruits[0]);

</script>

► This will give output : Apple

 241 views

134⟩ What are the different functional component in JavaScript?

The different components that are required in the functional model is :

First-class functions :

Fuctions that are first class will have some objects whose properties and methods are given by using the methods like length() and call(). These methods can be given different varibles and passed by an argumnent.

Nested functions :

These are the functions that are used in another function. It is created each time the outer function is invoked. If a function is used inside another then any constants, local variables and argument values, become part of the function object.

Closures :

JavaScript allows the function to be created with nested functionality. It usually try to find the combination of code that can be used to execute the application.

 248 views

135⟩ Explain the process of document loading in JavaScript?

When a document loads that means it is getting ready for the execution on the system. The document loads in the browser when there is a running of a document on the system. The applicaiton allows the JavaScript to look for all the properties that is given to the object and include all the property values that are used in the content that is being rendered for the page about to load. It is always a good practice to include the content in <SCRIPT> tags and statements in the Body portion of the document. This way the application gets loaded immediately.

<HTML>

<HEAD>

<TITLE>Immediate loading</TITLE>

</HEAD>

<BODY>

<H1>JavaScript used</H1>

<HR>

<SCRIPT LANGUAGE="Text/JavaScript">

<!-- Comments are used to hide from old browsers

document.write("Give the version " + navigator.appVersion)

document.write(" of <B>" + navigator.appName + "</B>.")

// end of the comment section -->

</SCRIPT>

</BODY>

</HTML>

 239 views

136⟩ What are the methods involved in JavaScript?

- Method is an informative that gets performed over an action that is related to the object. Method either performs on some object or affect any part of the the script or a document. Object can have as many number of methods that have associations with other objects. There is a method that is used by the JavaScript statement that includes a reference to an object this is given as :

document.orderForm.submit()

document.orderForm.entry.select()

- These are the functions which perform the dynamic interaction with the user. The first statement execute the element when pressed submit button to send a form to a server. These two statements are related to only the form. The scripts that are invoked will have the write of the document as well and will be written as :

document.write("Give the version " + navigator.appVersion)

document.write(" of <B>" + navigator.appName + "</B>.")

 249 views

137⟩ Explain JavaScript closures by example?

► The closure is a local variable of a function which remains alive after the function has returned.

► Closure combines a function with a local variable available at the time of creating closure.

► For example :

function wish(msg)

{

console.log(msg);

}

function greeting(name, occasion)

{

return name + ", Happy " + occasion;

}

var message = greeting ("Arpit", "Birthday");

// Pass it explicitly to wish

wish(message);

► By using closure we can simplify above code.

function greeting (name, occasion)

{

var msg = name + ", Happy " + occasion;

return function wish()

{

console.log(msg);

};

}

// create the closure

var wisharpit = greeting ("Arpit", "Birthday");

// use the closure

wisharpit ();

► Here wish function is nested within the greeting, so closure can access the local variable of greeting which are name, occasion and msg.

 239 views

140⟩ How are DOM utilized in JavaScript?

DOM stands for Document Object Model and is responsible for how various objects in a document interact with each other. DOM is required for developing web pages, which includes objects like paragraph, links, etc. These objects can be operated to include actions like add or delete. DOM is also required to add extra capabilities to a web page. On top of that, the use of API gives an advantage over other existing models.

 230 views