Created
December 26, 2019 03:36
-
-
Save bhaveshdaswani93/089ce078c7921682aa60c050613c3ca0 to your computer and use it in GitHub Desktop.
Imperative vs Declarative with example. Here i want you to understand what exactly these terms are
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Imperative: what to do and how to do | |
//Declarative: what to do and what should be done | |
// Task i want to loop through 1 to 5 and print in the console let see how we can do the code impertively as well as declaratively | |
//Imerative | |
for(i=1;i<=5;i++) { | |
console.log(i); | |
} | |
/* | |
In the above example i tell what to do console.log and how to do it like first declare i = 1, i should be less then 5, increment one by one | |
this is Imerative we have to specify each detail | |
*/ | |
//Declarative | |
[1,2,3,4,5].forEach(item=>console.log(item)); | |
/* | |
In the above example i am telling what to do console.log and here i am not telling how to do it , it is take care by forEach , that's | |
above code is declarative | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment