Syntactic sugar
Syntactic sugar is language notation that makes an existing operation or construct more concise or convenient to express without changing its computational meaning.
The Well-Grounded Rubyist, Fourth Edition
Syntactic sugar is a language feature that provides a more convenient or readable syntax for expressing an operation supported by the language's ordinary rules.
- How it is used
- Makes Ruby method calls read like assignment, arithmetic, indexing, or other familiar operations.
- How deep it goes
- Explains the method calls behind setter and operator notation, including custom definitions, shortcuts, semantic pitfalls, and non-overridable operators.
- Examples
- Uses a ticket price setter, normalized travel year, custom `+`, bank-account `-=`, and arithmetic written as explicit method calls.
- What you can do after
- Build it from scratch by defining setter or operator methods, and diagnose/debug surprising operator behavior by checking those methods.
Read how The Well-Grounded Rubyist, Fourth Edition explains syntactic sugar →
Secrets of the JavaScript Ninja, Second Edition
Language syntax that makes an operation easier to read or write without adding new underlying capabilities.
- How it is used
- Makes class-like object setup, function expressions, and iterator traversal shorter or clearer to write.
- How deep it goes
- Defines the idea through three comparisons, including class-to-prototype mechanics and iterator next/done handling.
- Examples
- Uses a Ninja class, a sorting callback, and a generator loop to compare concise syntax with its mechanics.
- What you can do after
- Understand how class, arrow-function, and for-of forms relate to prototypes, function expressions, and iterator operations.
Read how Secrets of the JavaScript Ninja, Second Edition explains syntactic sugar →
Also covered in
- Learn C++ by Example
- Python How-To
- JavaScript in DepthIn early access (MEAP)
- The Quick Python Book, Fourth Edition
- React Quickly, Second Edition
What to know first
- attributeAn attribute is a named property or piece of information associated with an entity, object, or structured data item.
- function argumentA function argument is a value or expression supplied when a function or method is invoked, providing input to the called operation.
- function expressionA function expression is an expression that creates a function value, which can be assigned, passed, or used within another expression.
Related concepts
- classequivalent to · A class is a programming-language construct that defines a type’s structure and behavior and provides a basis for creating or representing objects.
- accessor methodused by · An accessor method or function is a callable that reads, computes, or assigns a value associated with a property, field, or data element.
- CSS nestingincludes · CSS nesting is a stylesheet feature that allows rules to contain nested selectors and declarations expressing hierarchical or related selector structures.
- decoratorequivalent to · A decorator is a programming-language construct that adds metadata or behavior to, or transforms, a program declaration, often a function or class.
- do notationincludes · Do notation is Haskell syntax for sequencing monadic computations and binding their intermediate results in a readable, imperative-like form.
- function overloadingincludes · Function overloading is a programming-language feature in which one name denotes multiple callable signatures or implementations distinguished by parameter types or forms, with applicability determined by the call or context.
Questions about syntactic sugar
What is syntactic sugar?
Syntactic sugar is language notation that makes an existing operation or construct more concise or convenient to express without changing its computational meaning.
Which Manning books explain syntactic sugar?
The Well-Grounded Rubyist, Fourth Edition and Secrets of the JavaScript Ninja, Second Edition.
What should I know before learning syntactic sugar?
Manning books that teach syntactic sugar usually introduce attribute, function argument and function expression first.
What kinds of syntactic sugar are there?
Kinds of syntactic sugar include CSS nesting, do notation and function overloading.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

