InterviewSolution
Saved Bookmarks
| 1. |
How to work with external JavaScript file? |
|
Answer» In JavaScript, you can use the same variable to hold different data types. This is why it is called that JavaScript has dynamic types. It is not required to specify the type of variable in JavaScript. For example, the following is a variable, which is a number: var val = 10;Now, the same variable is a String: var val = “BINGO”;Now, you can also set it as a Number with decimal: var val = 3.6;Let us see them in an example to understand the dynamic types wherein we are showing the same variable can easily hold different types: <!DOCTYPE html> <html> <BODY> <H2>Dynamic Types</h2> <p id="myid"></p> <script> var a; // a is UNDEFINED a = "Bingo"; // a is a String a = 10; // a is a Number a = 3.6; // a is a Number with Decimal document.getElementById("myid").innerHTML = a; </script> </body> </html>The output: In the above example, we have set different types for the same variable “a”: var a; // a is undefined a = "Bingo"; // a is a String a = 10; // a is a Number a = 3.6; // a is a Number with Decimal |
|