JavaScript Number Properties

Property Description
EPSILON The difference between 1 and the smallest number > 1.
MAX_VALUE The largest number possible in JavaScript
MIN_VALUE The smallest number possible in JavaScript
MAX_SAFE_INTEGER The maximum safe integer (253 – 1)
MIN_SAFE_INTEGER The minimum safe integer -(253 – 1)
POSITIVE_INFINITY Infinity (returned on overflow)
NEGATIVE_INFINITY Negative infinity (returned on overflow)
NaN A “Not-a-Number” value

JavaScript EPSILON

Number.EPSILON is the difference between the smallest floating point number greater than 1 and 1. Continue reading JavaScript Number Properties

JavaScript Number Methods

JavaScript Number Methods

These number methods can be used on all JavaScript numbers:

Method Description
toString() Returns a number as a string
toExponential() Returns a number written in exponential notation
toFixed() Returns a number written with a number of decimals
toPrecision() Returns a number written with a specified length
valueOf() Returns a number as a number

The toString() Method

The toString() method returns a number as a string. Continue reading JavaScript Number Methods

JavaScript BigInt

JavaScript BigInt variables are used to store big integer values that are too big to be represented by a normal JavaScript Number.

JavaScript Integer Accuracy

JavaScript integers are only accurate up to 15 digits:

Integer Precision

let x = 999999999999999;
let y = 9999999999999999;

In JavaScript, all numbers are stored in a 64-bit floating-point format (IEEE 754 standard).

With this standard, large integer cannot be exactly represented and will be rounded.

Because of this, JavaScript can only safely represent integers:

Up to 9007199254740991 +(253-1)

and

Down to -9007199254740991 -(253-1).

Integer values outside this range lose precision. Continue reading JavaScript BigInt

JavaScript Numbers

JavaScript has only one type of number. Numbers can be written with or without decimals.

Example

let x = 3.14;    // A number with decimals
let y = 3;       // A number without decimals

 

Extra large or extra small numbers can be written with scientific (exponent) notation:

Example

let x = 123e5;    // 12300000
let y = 123e-5;   // 0.00123

Continue reading JavaScript Numbers

JavaScript Template Strings

Back-Tics Syntax

Template Strings use back-ticks (“) rather than the quotes (“”) to define a string:

Example

let text = `Hello World!`;

Quotes Inside Strings

Template Strings allow both single and double quotes inside a stringn : Continue reading JavaScript Template Strings

JavaScript String Search

JavaScript String indexOf()

The indexOf() method returns the index (position) of the first occurrence of a string in a string, or it returns -1 if the string is not found:

Example

let text = "Please locate where 'locate' occurs!";
let index = text.indexOf("locate");

Continue reading JavaScript String Search

JavaScript String Reference

JavaScript Strings

A JavaScript string stores a series of characters like “John Doe”.

A string can be any text inside double or single quotes:

let carName1 = "Volvo XC60";
let carName2 = 'Volvo XC60';

String indexes are zero-based:

The first character is in position 0, the second in 1, and so on. Continue reading JavaScript String Reference

JavaScript String Methods

JavaScript String Length

The length property returns the length of a string:

Example

let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let length = text.length;

Continue reading JavaScript String Methods

JavaScript Strings

Strings are for storing text

Strings are written with quotes

Using Quotes

A JavaScript string is zero or more characters written inside quotes.

Example

let text = "John Doe";

Continue reading JavaScript Strings

JavaScript Events

HTML events are “things” that happen to HTML elements.

When JavaScript is used in HTML pages, JavaScript can “react” on these events.

HTML Events

An HTML event can be something the browser does, or something a user does.

Here are some examples of HTML events:

  • An HTML web page has finished loading
  • An HTML input field was changed
  • An HTML button was clicked

Often, when events happen, you may want to do something. Continue reading JavaScript Events