Skip to guide content
[js] recap
Chapter 1 · Fundamentals Basis of JS

1.1

Basis of JS

Examples with a Run button are editable. Underlined terms open a short definition.

Basis of JS

  1. On page Script
<script type="text/javascript">
    ...
</script>
  1. Include external JS file
<script src="filename.js"></script>
  1. Output
console.log(a); // write to the browser console
document.write(a); // write to the HTML
alert(a); // output in an alert box
confirm('Really?'); // yes/no dialog, returns true/false depending on user click
prompt('Your age?', '0'); // input dialog. Second argument is the initial value
  1. Comments
/* Multi line
comment */
// One line
  1. Strict mode
'use strict'; // Use strict mode to write secure code
x = 1; // Throws an error because variable is not declared

Explore the idea

previous was assigned score’s primitive value before the reassignment.

score = 10previous = 10
Illustrative model. The controls step through the behavior described above.

Your last opened chapter is saved in this browser when local storage is available.

Discuss this section

Questions, corrections or a better example? Comments use GitHub Discussions.