Basics of JavaScript

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"]


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]]))

- The ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. You can not directly manipulate the contents of an ArrayBuffer; instead, you create one of the typed array objects or a DataView object which represents the buffer in a specific format, and use that to read and write the contents of the buffer.
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>

Post a Comment

0 Comments