The Basics:
For the sake of learning and not getting skewed results, I am scripting each piece of code within its own function. Within the foot of each page, the reader will find associated pages - for example "array methods" will feature in the foot of the array pages. The reader will also find links to useful sites such as w3schools/js. However, in the code examples pages, I hope to write code for each example - for example, all the DOM methods.
Comments within code:
// This is a single line comment.
/* This is a multi-line comment.
For larger comments that take more sentences. */
Outputting code on this website:
console.log
Writes or returns code in the
console
. To see code here, use the dev tools to inspect these pages and choose "console".An example:
alert
Writes or returns code as a popup alert.
An example:
document.write
- Writing text in the browser:
An example:
- Replacing text in the browser:
An example:
This text will be replaced
- Writing text in the browser:
Throughout this site, I will use the various methods, but especially document.write();
and alert();
because these will not need the reader going to the console.
At times, I may refer to an outside code host such as codepen:
See the Pen PozPaKw by Justin Sawyer (@JustinSawyer) on CodePen.
Variables:
var
var
can be redeclared.let
let
can not be redclared. Common practice dictates thatlet
is the best to use, so unless stated, all variabled here will be declared usinglet
.const
const
can not be redeclared. Ever. (When I say ever, I mean within its own script and those that communicate with it.)
They also have different levels of scope.
Data Types:
- Numbers
integer
A real number
floating-point number
orfloat
A number with decimal points.
- Special numbers
infinity, -infinity, NaN.
"strings"
[arrays]
[A set. Can be any type of data type, or a mixture of. Always enclosed with square brackets.]
Objects
`Textual data. A sentence, a word, number or character. Always enclosed with some kind of speech marks. The template literals surrounding this paragraph are the best to use, as they allow much more flexibility when writing code.`
Data that represents things rather than values. Object oriented principles are based on objects, instead of the actions and data.
function():
name function()
A function expression.
function name()
A function declaration.
The two give very different results. More information here.