var x, y; // How to declare variablesx = 5; y = 6; // How to assign valuesz = x + y; // How to compute values Strings are text, written within double or single quotes:
"John Doe"'John Doe' var x;x = 6; // x is assigned the value of 6<script> // In R.H.S. string "3" is converted into // number 3, hence returns true. document.write(9 == "9"); // used for next line document.write('<br>') // Here no type conversion takes place, // hence returns false document.write(9 === "9"); </script> Output:truefalseWrite a simple JavaScript program that on button click displays the current timestamp on screen.
<!DOCTYPE html><html><body><h2>My First JavaScript</h2><button type="button"onclick="document.getElementById('demo').innerHTML = Date()"> // using the Date() functionClick me to display Date and Time.</button><p id="demo"></p> // Using the id attribute</body></html>