TGViewer
Diyorbek.dev | 👨🏻‍💻 Diyorbek.dev | 👨🏻‍💻 @diyorbekk_dev · 380 subscribers
Post #717 114
#React
What difference between imperative and declarative programming?

Imperative Programming:

How to Achieve a Result: In imperative programming, you explicitly specify the steps or procedures that the computer must take to achieve a particular result.

Detailed Instructions: You provide a detailed sequence of statements, specifying how the program should perform each task.

Stateful: It often involves managing and updating the state of the program as it executes.

// Imperative example: Loop through an array
const numbers = [1, 2, 3, 4, 5];
for (let i = 0; i < numbers.length; i++) {
console.log(numbers[i]);
}


Declarative Programming:

What to Achieve: In declarative programming, you specify what you want to achieve without detailing how to achieve it.

Higher-Level Abstraction: Focus is on expressing the desired outcome rather than the step-by-step process.

Stateless: The emphasis is on immutability and avoiding the need for managing mutable states.

// Declarative example: Using map to transform an array
const numbers = [1, 2, 3, 4, 5];
const squaredNumbers = numbers.map(num => num * num);
console.log(squaredNumbers);


In Summary:
Imperative programming focuses on detailing the specific steps to achieve a result, often involving mutable states.
Declarative programming emphasizes describing the desired outcome, relying on higher-level abstractions and immutability.


@Diyorbekk_dev
  • 👍 1
  • 🔥 1
More from @diyorbekk_dev
  1. Sep 15, 2026ChatGPT and Codex now support TSRX syntax Highlighting! #tsrx #OctaneJS
  2. Sep 14, 2026Tanner Linsleydan yangilik. Hozirgacha Tanstack Team Octane uchun katta yordam berib kelmo…
  3. Sep 10, 2026Octane Js Hozirda Instagramda bitta content topoldim. Nasib tez kunda òzim yangiliklar qòy…
  4. Sep 9, 2026Ajoyib yangiliklardan biri. Tez orada Open AI butunlay òtadi nasib OctaneJs’ga. Tarqatmay…
  5. Sep 5, 2026Yangi joyni ham tizimlashtirdik. Bir qancha yangi imkoniyatlar qo‘shildi va yangi funksiya…
  6. Sep 5, 2026photo post
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →