JavaScript has dynamic types. This means that the same variable can be used as different types:
Example
var x; // Now x is undefined
var x = 5; // Now x is a Number
var x = "John"; // Now x is a String
JavaScript Strings
A string is a variable which stores a series of characters like "John Doe".
A string can be any text inside quotes. You can use single or double quotes:
Example:
<!DOCTYPE html>
<html>
<body>
<script>
var answer1="Welcome to ";
var answer2="'VCampus' is a learning community.";
document.write(answer1 + "<br>")
document.write(answer2 + "<br>")
</script>
</body>
</html>
Output:
JavaScript Numbers
JavaScript has only one type of numbers. Numbers can be written with, or without decimals:
Example:
<!DOCTYPE html>
<html>
<body>
<script>
var x=112.00;
var y=112e5;
var z=112e-5;
document.write(x + "<br>")
document.write(y + "<br>")
document.write(z + "<br>")
</script>
</body>
</html>
Comments 0