You know those features that you come across in your coding journey that just make your life easier the more you understand them? That’s rest parameters and spread syntax for me. I understand why a lot of early JavaScript fundamentals are taught without introducing these two ES6 features, but I’ve become more and more comfortable using them in my code and subsequently more appreciative of them.
Today I decided to go back to the early days of blogging where I would break down how I would solve a Codewars challenge. I enjoyed this challenge because it got me to think starting from the solution and work backward toward the beginning question. To me, this seems like one of those transferrable tasks that may look slightly different in a real world setting but the process of solving it would still be the same or similar.
As a beginner programmer, I often feel as though I’m in a state of constantly trying to level up my JavaScript knowledge. The more research I find, the more topics appear for which I have little or no knowledge. I like to Google different terms as ways to find benchmarks or goals to set for myself for taking small bites out of more complex topics.
I wanted to continue my streak of common JavaScript coding challenges with the Palindrome challenge. A Palindrome, according to Wikipedia, is:
“a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar.”
A good place to start is defining what these terms mean before we explain how to use them. In JavaScript, we can define a function in two ways: a declaration and an expression.
function sayHi(name) {
console.log(`Hi, ${name}!`);
};
sayHi("John");
When defining a funciton using a declaration, the function is hoisted which allows you to use a function before defining it. So, we could actually write the previous example like:
sayHi("John");
function sayHi(name) {
console.log(`Hi, ${name}!`);
};