<!DOCTYPE html>
<html>
<body>
<h2>Never Create Strings as objects.</h2>
<p>Strings and objects cannot be safely compared.</p>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<p id="demo4"></p>
<p id="demo5"></p>
<script>
var x = "John"; // x is a string
var y = new String("John"); // y is an object
document.getElementById("demo1").innerHTML = (x==y)+'<br>becz equal value';
var x = "John"; // x is a string
var y = new String("John"); // y is an object
document.getElementById("demo2").innerHTML = (x===y)+'<br>not equal becz one is string anothe is object';
var x = new String("John");
var y = new String("John");
document.getElementById("demo3").innerHTML = (x==y)+'<br>different object';
document.getElementById("demo4").innerHTML = "Hello" +
"Dolly!";
</script>
</body>
</html>
<html>
<body>
<h2>Never Create Strings as objects.</h2>
<p>Strings and objects cannot be safely compared.</p>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<p id="demo4"></p>
<p id="demo5"></p>
<script>
var x = "John"; // x is a string
var y = new String("John"); // y is an object
document.getElementById("demo1").innerHTML = (x==y)+'<br>becz equal value';
var x = "John"; // x is a string
var y = new String("John"); // y is an object
document.getElementById("demo2").innerHTML = (x===y)+'<br>not equal becz one is string anothe is object';
var x = new String("John");
var y = new String("John");
document.getElementById("demo3").innerHTML = (x==y)+'<br>different object';
document.getElementById("demo4").innerHTML = "Hello" +
"Dolly!";
</script>
</body>
</html>
No comments:
Post a Comment