<script>
and </script>
tagsscipt.js
and link it to the HTML file using: <script src="[file-name].js">
alert()
function will show a pop-up in the browser with the text<script language="javascript">
alert("Hello World");
</script>
document.write
function to change the content of the page. It will embed the html snippet <h1>Hello World</h1>
after the “First line”, but before the “Last line”.First line
<script>
document.write("<h1>Hello World</h1>");
</script>
Last line
console.log()
call. In order to see the console you’ll need to open it. If you happen to use Chrome on OSX you can open the console using: Command-Option-J.<script>
console.log("Hello World");
</script>
prompt()
function. Then, in this example we use the document.write
method to update the HTML with the text. The textbox will be pre-filled with the content of the second parameter. This can be very useful if we would like to ask the user to edit some value. We can pre-fill the box with the old value.<script>
var name = prompt("Your name:", "");
document.write("Hello ", name);
</script>
confirm()
function will show a pop-up window with the provided texts and with two buttons. If the user presses OK the confirm()
function will return true, if the user presses cancel or hits the ESC key, the function will return false.<script>
if (confirm("Shall I print Hello World?")) {
document.write("Hello World");
} else {
document.write("OK, I won't print it.");
}
</script>
let
const
const price1 = 5;
const price2 = 6;
let total = price1 + price2;
=
is an “assignment” operator, not an “equal to” operator.
x = x + 5
const pi = 3.14;
let person = "John Doe";
let answer = 'Yes I am!';
let x = 2 + 3 + "5";
undefined
)
let person = "John Doe", carName = "Volvo", price = 200;
$
and _
are valid variable names:let $ = "Hello World";
let $$$ = 2;
let _lastName = "Johnson";
let _x = 2;