Overview
Bracket notation refers to a method of accessing object properties in JavaScript using square brackets [] instead of dot notation. While dot notation uses a literal property name like obj.property, bracket notation allows dynamic access to properties using a string or variable, such as obj['property'] or obj[variable].
In the context of obfuscation, bracket notation is frequently used to obscure the true intent or structure of code. It makes it harder for static analysis tools or casual readers to immediately determine which properties or methods are being accessed. This technique is often combined with other obfuscation strategies to make code harder to reverse-engineer or understand.

Why It Matters
Bracket notation is especially relevant in secure development and obfuscation contexts, where developers must protect code from reverse engineering or unauthorized inspection. In production systems, this technique helps obscure logic or access patterns that could otherwise be exploited by attackers.
Additionally, bracket notation allows for dynamic property access, which is essential in scenarios where property names are determined at runtime. This flexibility is important for APIs, configuration systems, or plugin architectures, where hardcoding property names would limit extensibility.
How It Works
Bracket notation in JavaScript works by treating the content inside the brackets as a string key to access an object property. It supports both literal strings and variable expressions, making it a powerful tool for dynamic access. This mechanism is part of the core JavaScript language and is supported in all modern browsers and JavaScript environments.
- Bracket notation evaluates the expression inside the brackets and uses the result as a property key.
- It allows access to properties with special characters, spaces, or reserved keywords in their names.
- It enables dynamic property access using variables, which is useful in loops or conditional logic.
- Bracket notation can be used with computed property names in object literals, as in
{ [computedKey]: value }. - When used in obfuscation, it hides property names from static analysis by replacing direct references with string-based access.
Quick Reference
| Item | Purpose | Notes |
|---|---|---|
| Bracket notation syntax | Access object properties dynamically | Supports strings, variables, and expressions |
| Property key evaluation | Key is evaluated at runtime | Can be a variable or computed expression |
| Special character support | Access properties with spaces or symbols | Useful for dynamic or irregular keys |
| Obfuscation use case | Hide property names from static analysis | Combines with other obfuscation techniques |
| Performance consideration | Minor overhead compared to dot notation | Not a bottleneck in most applications |
Basic Example
The following example demonstrates basic bracket notation usage to access object properties dynamically.
const user = {
name: 'Alice',
age: 30,
'user-id': 12345
};
const key = 'name';
console.log(user[key]); // Outputs: Alice
const dynamicKey = 'user-id';
console.log(user[dynamicKey]); // Outputs: 12345
The first line accesses the name property using a variable. The second accesses a property with a dash using bracket notation, which is not possible with dot notation.
Production Example
In a production system, bracket notation is often used in configuration or plugin architectures where property names are not known at compile time.
const config = {
apiUrl: 'https://api.example.com',
timeout: 5000,
retries: 3
};
function getSetting(key) {
if (key in config) {
return config[key];
}
return null;
}
const setting = getSetting('apiUrl');
console.log(setting); // Outputs: https://api.example.com
This version is more suitable for production because it validates key existence before access, handles missing keys gracefully, and supports dynamic configuration access.
Common Mistakes
- Using bracket notation with undefined or null values, which results in errors or unexpected behavior.
- Confusing bracket notation with array access, leading to incorrect property access or syntax errors.
- Using bracket notation unnecessarily where dot notation would be clearer, reducing code readability.
- Not validating keys before access, which can lead to runtime errors or security vulnerabilities.
- Overusing obfuscation techniques like bracket notation, which can obscure legitimate code and hinder debugging or maintenance.
Security And Production Notes
- Bracket notation is not inherently insecure, but it can be misused in obfuscation to hide malicious behavior.
- Always validate keys before access to prevent unexpected runtime errors or access to unintended properties.
- Use bracket notation with caution in dynamic systems; ensure access is controlled and sanitized.
- Bracket notation can be used to bypass some static analysis tools, but modern tools can still detect obfuscation patterns.
- Performance impact is minimal, but in tight loops, dot notation may be slightly faster.
Related Concepts
Bracket notation is closely related to several core JavaScript concepts:
- Dot notation: Direct property access using a literal name, as in
obj.property. - Object property access: The general mechanism of accessing object members in JavaScript.
- Dynamic programming: Techniques that allow runtime decisions in code execution.
- Obfuscation: Methods used to make code harder to understand or reverse-engineer.
- Computed property names: A feature in ES6 where bracket notation is used in object literals to define dynamic keys.