JavaScript Assignment

JavaScript Assignment Operators

Assignment operators assign values to JavaScript variables.

Operator Example Same As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x – y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y
**= x **= y x = x ** y

Continue reading JavaScript Assignment

JavaScript Arithmetic

JavaScript Arithmetic Operators

Arithmetic operators perform arithmetic on numbers (literals or variables).

Operator Description
+ Addition
Subtraction
* Multiplication
** Exponentiation (ES2016)
/ Division
% Modulus (Remainder)
++ Increment
Decrement

Continue reading JavaScript Arithmetic

What’s the Popover API?

The Popover API provides a built-in way to create various types of popover used in web applications. Previously, these required you to use JavaScript, and take great care to implement them in an accessible manner. The API brings all of this to the browser, and a simple popover can be created declaratively in HTML.

Continue reading What’s the Popover API?

JavaScript Operators

Javascript operators are used to perform different types of mathematical and logical computations.

Examples:

The Assignment Operator = assigns values

The Addition Operator + adds values

The Multiplication Operator * multiplies values

The Comparison Operator > compares values

JavaScript Assignment

The Assignment Operator (=) assigns a value to a variable:

Assignment Examples

let x = 10;

Continue reading JavaScript Operators

JavaScript Const

The const keyword was introduced in ES6 (2015)

Variables defined with const cannot be Redeclared

Variables defined with const cannot be Reassigned

Variables defined with const have Block Scope

Cannot be Reassigned

A variable defined with the const keyword cannot be reassigned:

Example

const PI = 3.141592653589793;
PI = 3.14;      // This will give an error
PI = PI + 10;   // This will also give an error

Continue reading JavaScript Const

JavaScript Let

The let keyword was introduced in ES6 (2015)

Variables declared with let have Block Scope

Variables declared with let must be Declared before use

Variables declared with let cannot be Redeclared in the same scope

Block Scope

Before ES6 (2015), JavaScript did not have Block Scope.

JavaScript had Global Scope and Function Scope.

ES6 introduced the two new JavaScript keywords: let and const. Continue reading JavaScript Let

JavaScript Variables

Variables are Containers for Storing Data

JavaScript Variables can be declared in 4 ways:

  • Automatically
  • Using var
  • Using let
  • Using const

In this first example, x, y, and z are undeclared variables.

They are automatically declared when first used:

Example

x = 5;
y = 6;
z = x + y;

Continue reading JavaScript Variables

JavaScript Comments

JavaScript comments can be used to explain JavaScript code, and to make it more readable.

JavaScript comments can also be used to prevent execution, when testing alternative code.

Single Line Comments

Single line comments start with //.

Any text between // and the end of the line will be ignored by JavaScript (will not be executed).

This example uses a single-line comment before each code line:

Example

// Change heading:
document.getElementById("myH").innerHTML = "My First Page";

// Change paragraph:
document.getElementById("myP").innerHTML = "My first paragraph.";

Continue reading JavaScript Comments

HTML Unicode (UTF-8) Reference

Unicode is a universal character set that defines all the characters needed for writing the majority of living languages in use on computers.

Unicode aims to be (and already is) a superset of all other encoded computer character sets.

The Unicode Standard covers (almost) all characters, punctuations, and symbols in the world and enables processing, storage, and transport of text independent of platform and language.

The Unicode Consortium

The Unicode Consortium develops the Unicode Standard. The goal is to replace existing character sets with UTF (Unicode Transformation Format).

The Unicode Standard is implemented in HTML, XML, JavaScript, E-mail, PHP, Databases and in all modern operating systems and browsers.


The Unicode Character Sets

Unicode can be implemented by different character sets. The most commonly used encodings are UTF-8 and UTF-16:

Charset Description
UTF-8 A variable-length character encoding (1 to 4 bytes long). UTF-8 is backwards compatible with ASCII and the preferred encoding for e-mail and web pages.
UTF-16 A variable-length character encoding. UTF-16 is used in all major operating systems like Windows, IOS, and Unix.

The first 128 characters of UTF-8 have the same binary values as ASCII, making ASCII text valid UTF-8.


The HTML Standard is Unicode UTF-8

The default character set in HTML-4 (ISO-8859-1) were limited in size and not compatible in multilingual environments.

The default character encoding in HTML-5 is UTF-8.

HTML5 pages using a different character set than UTF-8 must specify this a <meta> tag:

Example

<meta charset=”ISO-8859-1″>

Continue reading HTML Unicode (UTF-8) Reference

JavaScript Syntax

JavaScript syntax is the set of rules, how JavaScript programs are constructed:

// How to create variables:
var x;
let y;

 

 

// How to use variables:
x = 5;
y = 6;
let z = x + y;

JavaScript Values

The JavaScript syntax defines two types of values:

  • Fixed values
  • Variable values

Fixed values are called Literals.

Variable values are called Variables. Continue reading JavaScript Syntax