Ans. JavaScript is a scripting language developed by Netscape. It can be used to program web browser or even servers. It can dynamically update the contents of the webpage, which is the beauty of JavaScript.
Ans. Using External JavaScript in our code has many advantages as stated below.
<!DOCTYPE html> <html> <body> <h2> <strong> Sample: Software Testing Help</strong> </h2> <p id="studentName"></p> <script> var studentName = "Prayag Verma"; // String 'Prayag Verma' stored in studentName var studentName; // varaible is decalred again document.getElementById("studentName").innerHTML = "Redeclaring the varaible will not lose the value!.<br>" +"Here the value in studentName is "+ studentName; </script> </body> </html>
Ans. This code will not produce any errors.
Ans. Redeclaration of the variables is allowed in JavaScript. Hence, the value of the variable will not be lost after the execution of the statement here.
var myObject = { foo: "bar", func: function() { var self = this; console.log("outer func: this.foo = " + this.foo); console.log("outer func: self.foo = " + self.foo); (function() { console.log("inner func: this.foo = " + this.foo); console.log("inner func: self.foo = " + self.foo); }()); } }; myObject.func();
Ans. In the outer function, both this and self refer to myObject and therefore both can properly reference and access foo.
Ans. In the inner function, though, this no longer refers to myObject. As a result, this.foo is undefined in the inner function, whereas the reference to the local variable self remains in scope and is accessible there.
Ans. Some of the advantages of JavaScript are:
Ans. Some of the disadvantages of JavaScript are:
Ans. The function which has named at the time of definition is called a named function. For example
function msg() { document.writeln("Named Function"); } msg();
Ans. It is a function that has no name. These functions are declared dynamically at runtime using the function operator instead of the function declaration. The function operator is more flexible than a function declaration.
var display=function() { alert("Anonymous Function is invoked"); } display();
Ans. DOM stands for Document Object Model. A document object represents the HTML document. It can be used to access and change the content of HTML
Ans. The innerText property is used to write the simple text using JavaScript dynamically. Let's see a simple example:
document.getElementById('mylocation').innerText="This is text using JavaScript";
Ans.
Ans.
Ans. The cursor can be set to wait in JavaScript by using the property "cursor". The following example illustrates the usage:
<script> window.document.body.style.cursor = "wait"; </script>