Dynamic Web Pages with JavaScript - Reading Notes

Dynamic Web Pages with JavaScript - Reading Notes

View the full blogs:

JS Intro Paragraph

Input and Output in JS

Variables

JavaScript is a prototype-based, multi-paradigm, slingle-threaded, dynamic language, supporting object-oriented, imperative, and declarative styles.

Do not confuse JavaScript with Java programming language.

Visit the link for “JS Intro Paragraph” above for access to several tutorials ranging from beginner to advanced.

Four Ways to Declare a JavaScript Variable

Variables are containers for storing data (storing data values)

For example: Declate that ‘x’ is a variable by writing ‘var x’ followed by = a value ‘5’. This says that x stores the value 5. You can replace ‘var’ with ‘let’, ‘const’, or nothing and they will all mean the same thing.

JavaScript Indentifiers

All JavaScript variables must be identified with unique names called identifiers

Rules for consrtucting names for variables:

The = is an assignment operator not an “equal to” operator, meaning it’s just telling you what the variable stands for

Variables can be numbers or text, and text is referred to as text strings. So, variables are numbers and strings. Strings are written inside double or single quotes, numbers do not have quotes

Note: Its good programming practice to declare all variables at the beginning of a script

One statement, many variables: if on one line, separate the variables with commas. Or put on one each following line.

Value = undefined if something has to be calculated or provided later. For example: let carName;

You can re-declare JavaScript variables with ‘var’ and it will not lose it’s original value, but this will not work with ‘let’ or ‘const’

JaveScript Arithmetic using operators like = and +. For example: let x = 5 + 2 + 3; which with show 10 OR let x = “John” + “ “ + “Doe”; which will show John Doe. NOTE a number in quotes makes the other numbers strings and will be concatenated. For example: let x = 2 + 3 + “5”; which will show 55.

JavaScript treats a dollar sign as a letter, identifiers containing $ are valid variable names

JavaScript treats underscore as a letter, identifiers containing _ are valid variable names

Return home