Q. What is arguments object?
A. The "arguments" Object is an Array which is a local variable available within function. Scope of "arguments" object is restricted inside the function.
function testDemo(){
console.log(arguments);
}
testDemo(1, "JavaScript");
Output:
[1, "JavaScript"]
A. “==” 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.
testDemo(1, "JavaScript");
Output:
[1, "JavaScript"]
Q. Difference between undefined and null?
A. "undefined" is a global property in JavaScript whose value is undefined. So when a variable has not assigned a value JavaScript assign undefined to it. When you typeof undefined you will get undefined as value.
While "null" represent object which has empty value. When typeof null you will get object as value.
Q. Explain the difference between “==” and “===”?
A. “==” 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.
Q. Difference between Array and ArrayBuffer?
A. - The JavaScript Array global object is a constructor for arrays, which are high-level, list-like objects.
Syntax:
new Array(element0, element1[, ...[, elementN]]))
Syntax:
new ArrayBuffer(length)
Q. What is the use of eval() method?
A. The eval() method evaluates JavaScript code represented as a string.
Syntax:
eval(String)
index.html
<html>
<head>
<script>
function test(){
var testScript = document.getElementById("textArea").value;
eval(testScript);
}
</script>
</head>
<body>
<textarea id="textArea">alert("hello");</textarea>
<input type="button" onclick="test()" value="Run">
</body>
</html>
<html>
<head>
<script>
function test(){
var testScript = document.getElementById("textArea").value;
eval(testScript);
}
</script>
</head>
<body>
<textarea id="textArea">alert("hello");</textarea>
<input type="button" onclick="test()" value="Run">
</body>
</html>
0 Comments