Imperative vs Declarative Programming with Examples
?????????? ???????? ????
└? Frontend Engineer (10+ yrs) | React.js & Next.js Expert | TypeScript | Team Lead & Mentor | High-Performance Web Solutions??
Imperative programming is 'how' you do something, and declarative programming is more like 'what' you do.
Let's try to explain imperative and declarative programming with examples:
Example 1: You and your husband went to a restaurant.
Explanation: The imperative approach is concerned with how you're actually going to get a seat. You need to list out the steps, to be able to show how you're going to get a table. The declarative approach is more concerned with what you want, a table for two.
Example 2: I'm right next to Wal-Mart. How do I get to your house from here?
Explanation: Regardless of how I get to your house, what really matters is the car I drive. Am I going to drive an imperative stick shift car or a declarative automatic car?
Example 3: Check the following codes