You ever defined a constant with value `1 << 2`?
In this article, we review a particular way of defining constants found in Ripple codebase. We will look at:
-
What is Ripple?
-
constants.js file
-
What is 1 << 1?

What is Ripple?
Ripple is the elegant TypeScript UI framework, created by Dominic Gannaway, author of lexicaljs and infernojs.
Learn more about Ripple.
constants.js file
You will find the below code in ripple/packages/ripple/…/constants.js file:
export const TEMPLATE_FRAGMENT = 1; export const TEMPLATE_USE_IMPORT_NODE = 1 << 1; export const IS_CONTROLLED = 1 << 2;
What I found interesting is the bitwise operator, <<, used.
What is 1 << 1?
This is bitwise flagging using the bitwise left shift operator (<<)
ChatGPT provided the below explanation:`
1in binary:
0001
1 << 1→ shift left by 1:
0010 // which is 2 in decimal
1 << 2→ shift left by 2:
0100 // which is 4 in decimal
About me:
Hey, my name is Ramu Narasinga. Email: ramu.narasinga@gmail.com
Tired of AI-generated code that works but nobody understands?
I spent 3+ years studying OSS codebases and wrote 350+ articles on what makes them production-grade. I built an open source tool that reviews your PR against your existing codebase patterns.
Your codebase. Your patterns. Enforced.