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.

Hot sauce if you're wrong - web dev trivia for staff engineers

Hot sauce if you're wrong · web dev trivia for staff engineers (Chris vs Jeremy, Leet Heat S1.E4)

  • Shipping Fast: Test your knowledge of deployment strategies and techniques
  • Authentication: Prove you know your OAuth from your JWT
  • CSS: Demonstrate your styling expertise under pressure
  • Acronyms: Decode the alphabet soup of web development
  • Accessibility: Show your commitment to building for everyone

Contestants must answer rapid-fire questions across the full stack of modern web development. Get it right, earn points. Get it wrong? The spice level goes up!

Watch Video 🌶️🔥

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay