---
title: Declarative vs Imperative Programming
description: What is the difference between imperative and declarative programming?
image:
tags: reactjs
lintConfig:
MD004:
style: "consistent"
MD006: false
published: true
---
# Declarative vs Imperative Programming
**Imperative programming** is a way of describing how things work. It explicitly specifies each statement, mutating a program’s state.
**Declarative programming** expresses the logic without explicitly specifying its control flow. It is a way of describing what you want to do, without listing all the steps to make it work.
- simple, easier to read, elegant code
- requires less effort to be understood
- no need to use variables
- avoids creating and mutating the state
Let's check if a number's a palindrome the *imperative* way:
```javascript=
function isPalindrome(word) {
const len = word.length;
for (let i = 0; i < len / 2; i++) {
if (word[i] !== word[len - 1 - i]) {
return false;
}
}
return true;
}
```
A *declarative* solution would be:
```javascript=
function isPalindrome(word) {
return word == word.split('').reverse().join('')
}
```