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

JavaScript Object Constructors

Object Constructor Functions

Sometimes we need to create many objects of the same type.

To create an object type we use an object constructor function.

It is considered good practice to name constructor functions with an upper-case first letter.

Object Type Person

function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}

Continue reading JavaScript Object Constructors

JavaScript Display Objects

How to Display JavaScript Objects?

Displaying a JavaScript object will output [object Object].

Example

// Create an Object
const person = {
  name: "John",
  age: 30,
  city: "New York"
};

document.getElementById("demo").innerHTML = person;

Continue reading JavaScript Display Objects