81⟩ Explain how to detect the operating system on the client machine?
In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used.
“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”
In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used.
It can be done in the following way:
JavaScript
document.getElementById("myText").style.fontSize = "20?;
or
document.getElementById("myText").className = "anyclass";
"==" checks only for equality in value whereas "===" is a stricter equality test and returns false if either the value or the type of the two variables are different.
<html>
<head> <title>t1</title>
<script type="text/javascript">
function addNode() { var newP = document.createElement("p");
var textNode = document.createTextNode(" This is a new text node");
newP.appendChild(textNode); document.getElementById("firstP").appendChild(newP); }
</script> </head>
<body> <p id="firstP">firstP<p> </body>
</html>
JavaScript is a client-side scripting language that can be inserted into HTML pages and is understood by web browsers.
No. JavaScript does not have concept level scope. The variable declared inside the function has scope inside the function.
'This' keyword is used to point at the current object in the code. For instance: If the code is presently at an object created by the help of the 'new' keyword, then 'this' keyword will point to the object being created.
'Typeof' is an operator which is used to return a string description of the type of a variable.
There are two ways to read and write a file using JavaScript
► Using JavaScript extensions
► Using a web page and Active X objects
Escape characters (Backslash) is used when working with special characters like single quotes, double quotes, apostrophes and ampersands. Place backslash before the characters to make it display.
Example:
document.write "I m a "good" boy"
document.write "I m a "good" boy"
Unshift method is like push method which works at the beginning of the array. This method is used to prepend one or more elements to the beginning of the array.
Cookies are the small test files stored in a computer and it gets created when the user visits the websites to store information that they need. Example could be User Name details and shopping cart information from the previous visits.
Try… Catch-finally is used to handle exceptions in the JavaScript
JavaScript
Try{
Code
}
Catch(exp){
Code to throw an exception
}
Finally{
Code runs either it finishes successfully or after catch
}
The onload function is not run until all the information on the page is loaded. This leads to a substantial delay before any code is executed.
onDocumentReady loads the code just after the DOM is loaded. This allows early manipulation of the code.
Yes, JavaScript is case sensitive. For example, a function parseInt is not same as the function Parseint.
Closure is a locally declared variable related to a function which stays in memory when the function has returned.
For example:
JavaScript
function greet(message) {
console.log(message);
}
function greeter(name, age) {
return name + " says howdy!! He is " + age + " years old";
}
// Generate the message
var message = greeter("James", 23);
// Pass it explicitly to greet
greet(message);
This function can be better represented by using closures
function greeter(name, age) {
var message = name + " says howdy!! He is " + age + " years old";
return function greet() {
console.log(message);
};
}
// Generate the closure
var JamesGreeter = greeter("James", 23);
// Use the closure
JamesGreeter();
Assigning properties to objects is done in the same way as a value is assigned to a variable. For example, a form object's action value is assigned as 'submit' in the following manner - Document.form.action="submit"
This method is functional at the starting of the array, unlike the push(). It adds the desired number of elements to the top of an array. For example -
var name = [ "john" ];
name.unshift( "charlie" );
name.unshift( "joseph", "Jane" );
console.log(name);
The output is shown below:
[" Jane ", " joseph ", " charlie ", " john "]
The different functional components in JavaScript are-
First-class functions:
Functions in JavaScript are utilized as first class objects. This usually means that these functions can be passed as arguments to other functions, returned as values from other functions, assigned to variables or can also be stored in data structures.
Nested functions:
The functions, which are defined inside other functions, are called Nested functions. They are called 'everytime' the main function is invoked.
Java is a complete programming language. In contrast, JavaScript is a coded program that can be introduced to HTML pages. These two languages are not at all inter-dependent and are designed for the different intent. Java is an object - oriented programming (OOPS) or structured programming language like C++ or C whereas JavaScript is a client-side scripting language and it is said to be unstructured programming.