Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JavaScript hoisting, objects, this, and new are related, but they are not one shared “context” rule. To predict what code does, track when a binding is initialized, where a property is found, how a function is called, and whether construction creates a new receiver.

How JavaScript objects and property lookup work

An object is a collection of properties whose keys are strings or symbols. A property’s value can be data, another object, or a function. Use dot notation when the property name is a valid identifier, or bracket notation when it is computed or otherwise needs quoting:

const user = {
  name: "Mina",
  "favorite color": "blue"
};

user.name;                 // "Mina"
user["favorite color"];    // "blue"
user.name = "Ravi";

A function stored in an object property is commonly called a method. That label describes how the function is being used; it does not permanently bind the function to that object.

When JavaScript looks up a property, it first checks the object itself. If the property is not there, lookup can continue through the object’s prototype chain. An object’s own property can therefore shadow an inherited property with the same name. Not every object inherits from Object.prototype; an object can instead have a null prototype. See MDN’s guide to working with objects for more property examples.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Own properties and shared prototype properties

Properties placed on a prototype can be shared through lookup by instances linked to that prototype. They do not become own properties on each instance. For example, if a constructor’s prototype supplies a start method, instances can use it without each storing a separate start property. Assigning car1.color, by contrast, creates or updates a property on car1; it does not set the color on other instances. An own property can also shadow a prototype property for that instance.

What hoisting means—and what it does not mean

Hoisting is a shorthand for observable declaration behavior, not a claim that JavaScript physically moves source lines before running them. MDN notes that “Hoisting is not a term normatively defined in the ECMAScript specification.” A more useful way to reason about it is to ask whether a binding exists at a point in the code, whether it has been initialized, and what value is available there. The answer depends on the declaration type and scope. See MDN’s hoisting explanation.

var is available as undefined before its assignment

A var binding is initialized to undefined before the assignment runs. Reading it earlier does not read the later assigned value:

console.log(a); // undefined
var a = 1;
console.log(a); // 1

This behavior does not move the assignment. The first log runs before a = 1.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

let and const have a temporal dead zone

Lexical declarations such as let, const, and class are associated with their scope before their declaration executes, but they cannot be accessed until initialized. Accessing one earlier throws a ReferenceError; the interval is called the temporal dead zone.

console.log(b); // ReferenceError
let b = 1;

This is a separate example: an uncaught exception stops execution at that line, so do not place it after the var example if you expect the rest of the same script to run.

Function declarations and imports

Function declarations can be called earlier in their scope than their textual position. Imports also have early availability semantics. These facts do not make all declarations interchangeable: var, lexical declarations, functions, and imports have different initialization and scope rules.

How this is chosen for a regular function

MDN’s concise rule is: “The value of this in JavaScript depends on how a function is invoked (runtime binding), not how it is defined.” For a regular function, inspect the call expression rather than where the function was written or stored. See MDN’s this reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

A method call supplies its receiver

In obj.method(), the object immediately to the left of the call supplies the receiver, so the method’s this is obj. Moving the same function into a standalone variable changes the call form:

"use strict";

const first = { value: 10, read() { return this.value; } };
const second = { value: 20 };

first.read(); // 10
second.read = first.read;
second.read(); // 20

const read = first.read;
read(); // TypeError when it tries to read this.value

In strict mode, the standalone call has this === undefined; the error above occurs because the function then tries to read value from undefined. In non-strict mode, a standalone regular-function call with an undefined or null receiver substitutes globalThis instead. The function’s result then depends on the properties and environment involved.

Explicitly set a regular function’s receiver

call and apply invoke a function with a chosen receiver; apply takes arguments as an array-like value. bind returns a new function whose receiver is fixed:

function readValue() { return this.value; }
const item = { value: 7 };

readValue.call(item);       // 7
readValue.apply(item, []);  // 7
const readItem = readValue.bind(item);
readItem();                 // 7

Passing a callback does not by itself preserve the receiver from where it was defined. The API that invokes the callback determines the call behavior, so check that API’s contract when its this value matters.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Arrow functions capture the surrounding this

An arrow function does not create its own this; it uses the value from its surrounding lexical scope. This makes arrows useful for callbacks that should retain an enclosing method’s receiver:

const counter = {
  count: 0,
  start() {
    const tick = () => { this.count += 1; };
    tick();
    return this.count;
  }
};

counter.start(); // 1

Because an arrow’s this is lexical, call, apply, and bind cannot replace it. Arrows are usually a poor choice for an object method when the intention is for the call site to select the receiver. An object literal also does not create a new this scope.

Top-level this depends on the environment

Do not infer a universal top-level value. In a browser classic script, top-level this is generally globalThis (the browser’s window). At the top level of a JavaScript module it is undefined. Node.js CommonJS wraps module code, so its top-level value differs from both cases.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What the new operator does

new Constructor() creates an object and calls the constructor with that object as this. In practical terms, the process is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
  1. Create a fresh object.
  2. If the constructor’s prototype is an object, link the fresh object to it for property lookup.
  3. Call the constructor with the fresh object as this.
  4. Return the constructor’s explicit non-primitive object result, if it returned one; otherwise return the fresh object.

For example, an instance can find describe through Car.prototype, while color is stored directly on that instance:

function Car(color) {
  this.color = color;
}
Car.prototype.describe = function () {
  return `A ${this.color} car`;
};

const car1 = new Car("red");
car1.describe(); // "A red car"

The prototype link supports inherited lookup; it does not copy prototype properties onto the instance. MDN documents the operator’s behavior and constructor examples in its new operator reference.

Constructor return values can change the result

If a constructor explicitly returns a different non-primitive object, that object becomes the result of the new expression instead of the fresh instance. A primitive return value, such as a string or number, is ignored for this purpose, and the fresh object is returned.

Classes and constructor edge cases

  • A class constructor must be called with new; calling a class as an ordinary function throws TypeError.
  • An ordinary constructor function can be called without new, but that does not create an instance. Its this then follows ordinary function-call rules.
  • new.target can be used inside a function or constructor to detect whether it was invoked with new.
  • Not every callable value is constructible. Arrow functions are not constructors, and some built-in functions are callable only or constructible only.

A practical way to predict JavaScript behavior

  1. For a variable read: identify its declaration and scope, then ask whether it has been initialized at that line. Distinguish var’s initial undefined from the temporal dead zone for lexical declarations.
  2. For a property read: check the object’s own properties first, then follow its prototype chain until the property is found or lookup ends.
  3. For this in a regular function: inspect how the function is called. Check for a method receiver, an explicit call/apply/bind, or a standalone call and its strictness.
  4. For this in an arrow: look outward to the lexical scope where the arrow was created; the call site cannot replace that binding.
  5. For new: identify the constructor’s prototype, the receiver used during the call, and whether the constructor returns another object.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.