Humans experience peak motivation when working on tasks that are right on the edge of their current abilities.
This is known as The Goldilocks Rule in [Atomic Habits] and I've found it to be absolutely true. A comfortable position is a boring position, and in the long term often does a disservice to your career. A position that forces you to grow has multiple complementary benefits.
The first and most obvious is the growth itself. Adding new skills to your bag of tricks is valuable on its face. That said, in most fields but especially technology, evolving your skills is a requirement, not a luxury. Deciding you're not going to expand your abilities, or more commonly just getting too comfortable and letting your skills atrophy, is a recipe for disaster. Heck, the technology I used to make a living a decade ago literally doesn't exist today.
Given these realities, you need to invest time in growing your skills and learning new things. Wouldn't it be nice if you got paid to do it? If you didn't have to use nights and weekends to stay current? That's exactly what a challenging job enables you to do.
I've done it both ways, and I greatly prefer daytime, on the job learning to late night sessions on the couch after everyone else is asleep.
This growth also kick starts a virtuous cycle for you and your employer. The skills you learn out of necessity in your position inherently make you more valuable to your organization. That means you can make a bigger impact. You can take on a larger role when the time comes, and you know you can grow within the company, engendering loyalty and employee retention.
I realized early in my career that the ultimate purpose of what I was building mattered to me. I wasn't drawn to the projects that a lot of my co-workers seemed to find the most exciting. Building the promotional site for some upcoming movie did nothing to motivate me. Building a site that displays and explains school system data? Now we're talking.
It doesn't have to be world saving or perfectly altruistic, but it should be a topic of personal interest or importance with redeeming qualities. On balance, it should improve the world in some facet besides just making money for the people signing the checks.
Finally, I've experienced and observed enough companies to know that the personal and organizational dynamics can make or break an experience.
At the most basic level, of course, there is a need for respect, professionalism, kindness, and decency between all members of the organization. Toxic workplaces exist and they are unacceptable.
Once those and other baseline needs are met, things like institutional belief in [The Correlation Principle] quickly become important. A shared and preferably documented understanding of what constitutes "quality" enables many key follow-on activities like code review and cross team collaboration to be done consistently and effectively across the organization.