JavaScript Descriptive Question :
1. What is history object? Write methods of it.
The history object contains the URLs visited by the user (within a browser window). The history object is part of the window object and is accessed through the window.history property. history object has a single property named length and three methods back(), forward() and go().
2. What do you mean by cookies?
A cookie is a variable that is stored on the visitor's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With JavaScript, we can both create and retrieve cookie values. Cookies are small bits of text files that store our session, and other small data, it’s pretty much like a database in a sense.
3. What is reserved word? Write five reserved word.
Reserved words are some of words those actually used in the Java Script language, and are reserved in JavaScript for compatibility purposes or as possible extensions. When choosing names for JavaScript variables or function, we have to avoid these reserved words!
Some reserved words are as follows:
abstract else instanceof super boolean enum int switch
4. Write about ‘interpreted’ and ‘loosely typed language’ according to JavaScript?
JavaScript is an interpreted language (means that scripts execute without preliminary compilation). We need to compile the code when we convert a high level language to a machine level executable code and here we don’t need to convert the language. JavaScript don’t need to compile the code; it’s a script which tells the web browser what to do. It is used to access the object within other application (web browser).
Loose typing means that variables are declared without a type. This is in contrast to strongly typed languages that require typed declarations.
5. What do you mean by events and events handler?
Events: An event is something that happens, e.g. a mouse click on a button, an image that has loaded. Events usually occur as a result of human interaction with the browser, e.g. selecting a document to load, entering form information.
Event Handler: Event handlers are JavaScript methods, i.e. functions of objects, that allow us as JavaScript programmers to control what happens when events occur.
6. What is the difference between setInterval() and setTimeout()
setTimeout() allows us to tell the user’s browser to perform some Javascript in X milliseconds. The Javascript executed can be a function call, a single line of Javascript, etc.
For example:
setTimeout(“alert(‘Hello, World!’)”, 5000);
setInterval() is very similar to the above, the key difference is that it repeatedly runs the same Javascript at the specified time.
For example:
setInterval(“alert(‘Hello, World!’)”, 5000);
7. What is the difference between substring() and substr()?
JavaScript substring is used to take a part of a string. The syntax of JavaScript substring method is given below: stringObjectToTakeAPartOf.substring(start-index,stop-index) // stop-index is Optional
The JavaScript substr() method works slightly different. Instead of the second parameter being an index number, it gives the number of characters. The syntax of JavaScript substr() is given below:
stringObjectToTakeAPartOf.substr(start-index,length)
8. What is the function of charAt()?
The charAt() method returns the character at the specified index in a string.
The index of the first character is 0, and the index of the last character in a string called "txt", is txt.length-1.
Syntax: string.charAt(index)
9. What is the function of indexOf()?
The indexOf() method returns the position of the first occurrence of a specified value in a string.
This method returns -1 if the value to search for never occurs.
string.indexOf(searchstring)
10. What is function? How can you define function in JavaScript?
Functions in JavaScript let you define code that is called on demand, instead of immediately. There are several ways to define a function:
Standard function Statement:
function getarea(w,h)
{ //standard function
var area=w*h
return area
}
getarea(3,5) //calls function
Function Literal (an anonymous function assigned to a variable):
var getarea=function(w,h)
{
var area=w*h
return area
}
getarea(3,5) //calls function
Function Constructor (creates a function on the fly, which is slower and generally discouraged):
//syntax: new Function(argument1, argument2, ..., argumentY, functionbody) //all parameters must be a string
var getarea=new Function("w", "h", "var area=w*h; return area")
getarea(3,5) //calls function
1. What is history object? Write methods of it.
The history object contains the URLs visited by the user (within a browser window). The history object is part of the window object and is accessed through the window.history property. history object has a single property named length and three methods back(), forward() and go().
2. What do you mean by cookies?
A cookie is a variable that is stored on the visitor's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With JavaScript, we can both create and retrieve cookie values. Cookies are small bits of text files that store our session, and other small data, it’s pretty much like a database in a sense.
3. What is reserved word? Write five reserved word.
Reserved words are some of words those actually used in the Java Script language, and are reserved in JavaScript for compatibility purposes or as possible extensions. When choosing names for JavaScript variables or function, we have to avoid these reserved words!
Some reserved words are as follows:
abstract else instanceof super boolean enum int switch
4. Write about ‘interpreted’ and ‘loosely typed language’ according to JavaScript?
JavaScript is an interpreted language (means that scripts execute without preliminary compilation). We need to compile the code when we convert a high level language to a machine level executable code and here we don’t need to convert the language. JavaScript don’t need to compile the code; it’s a script which tells the web browser what to do. It is used to access the object within other application (web browser).
Loose typing means that variables are declared without a type. This is in contrast to strongly typed languages that require typed declarations.
5. What do you mean by events and events handler?
Events: An event is something that happens, e.g. a mouse click on a button, an image that has loaded. Events usually occur as a result of human interaction with the browser, e.g. selecting a document to load, entering form information.
Event Handler: Event handlers are JavaScript methods, i.e. functions of objects, that allow us as JavaScript programmers to control what happens when events occur.
6. What is the difference between setInterval() and setTimeout()
setTimeout() allows us to tell the user’s browser to perform some Javascript in X milliseconds. The Javascript executed can be a function call, a single line of Javascript, etc.
For example:
setTimeout(“alert(‘Hello, World!’)”, 5000);
setInterval() is very similar to the above, the key difference is that it repeatedly runs the same Javascript at the specified time.
For example:
setInterval(“alert(‘Hello, World!’)”, 5000);
7. What is the difference between substring() and substr()?
JavaScript substring is used to take a part of a string. The syntax of JavaScript substring method is given below: stringObjectToTakeAPartOf.substring(start-index,stop-index) // stop-index is Optional
The JavaScript substr() method works slightly different. Instead of the second parameter being an index number, it gives the number of characters. The syntax of JavaScript substr() is given below:
stringObjectToTakeAPartOf.substr(start-index,length)
8. What is the function of charAt()?
The charAt() method returns the character at the specified index in a string.
The index of the first character is 0, and the index of the last character in a string called "txt", is txt.length-1.
Syntax: string.charAt(index)
9. What is the function of indexOf()?
The indexOf() method returns the position of the first occurrence of a specified value in a string.
This method returns -1 if the value to search for never occurs.
string.indexOf(searchstring)
10. What is function? How can you define function in JavaScript?
Functions in JavaScript let you define code that is called on demand, instead of immediately. There are several ways to define a function:
Standard function Statement:
function getarea(w,h)
{ //standard function
var area=w*h
return area
}
getarea(3,5) //calls function
Function Literal (an anonymous function assigned to a variable):
var getarea=function(w,h)
{
var area=w*h
return area
}
getarea(3,5) //calls function
Function Constructor (creates a function on the fly, which is slower and generally discouraged):
//syntax: new Function(argument1, argument2, ..., argumentY, functionbody) //all parameters must be a string
var getarea=new Function("w", "h", "var area=w*h; return area")
getarea(3,5) //calls function
Tags
Javascript