DEV Community

Cover image for The JavaScript Banana 🍌
JS Bits Bill
JS Bits Bill

Posted on β€’ Edited on

3

The JavaScript Banana 🍌

You gotta make programming fun once in a while. Why not have a banana!

('b'+'a'+ +'🍌'+'a').toUpperCase();
// BANANA
Enter fullscreen mode Exit fullscreen mode

WTF! πŸ™‰
Depending on the context, + in JavaScript will function as the unary operator to convert an operand into a number. The first plus sign is used to concatenate the "b" and "a" strings while the third is used to convert 🍌 to a Number type - and this returns NaN. Add a trailing "a", use another + to concatenate "ba" + NaN + "a", set it to all caps, and we get BANANA!

 

Bonus Shenanigans

See what this returns in the Chrome console!

const p1 = (+'πŸ¦‡'+'a'+ +'πŸ‘¨'+'a').repeat(2);

const str = window.BatteryManager.toString();
const p2 = str.slice(9, 19).replace('tery', '');

console.log(`${p1} ${p2.toUpperCase()}!`);
Enter fullscreen mode Exit fullscreen mode

Check out more #JSBits at my blog, jsbits-yo.com. Or follow me on Twitter!

Image of Timescale

πŸš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsβ€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay