DEV Community

Joe Steinbring
Joe Steinbring

Posted on • Originally published at blog.jws.app on

Fun with string concatenation

Previously (on my other blog), we looked at string concatenation and I figured that this week, we could see what you could actually do with it. Back in 2014, I used a calculator to play around with PhoneGap. It might be time to play with the concept again.

In the above example, we have a value stored as “value” and as you click buttons on the calculator, it appends to the “value” string. The eventual evaluation of the string’s numerical value is done using eval(). It is admittedly a much less than perfect calculator, though. Once you hit “=”, the whole thing kind of breaks down. Let’s try again.

This example still uses addExpresion(), clear(), and the computed value of displayValue but it is less dependent on slice() and hacky cheats.

So, can we simplify this a little? Sure!

You’ll notice that in the third iteration, I removed an unnecessary condition (that was looking for the clicking of an operator button).

Have a suggestion of how to improve it further? Feel free to drop a comment, below.

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

If this **helped, please leave a ❤️ or a friendly comment!

Okay