What is the difference between a declaration and a definition? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between a declaration and a definition?

Hi friends, I wanted to ask why in some texts the definition word is used and in other the declaration word is used? What is the difference between these two words? For example, in the following text, can the word define be used instead of declare? JavaScript uses the var keyword to declare variables.

29th Aug 2020, 4:09 PM
Morteza R.g
Morteza R.g - avatar
2 Answers
+ 5
Declaration of a variable is for informing to the compiler the following information: name of the variable, type of value it holds and the initial value if any it takes. i.e., declaration gives details about the properties of a variable. Whereas, Definition of a variable says where the variable gets stored. i.e., memory for the variable is allocated during the definition of the variable. For more info visit👇 https://www.geeksforgeeks.org/difference-between-definition-and-declaration/
29th Aug 2020, 4:17 PM
Arsenic
Arsenic - avatar
+ 3
Declaring.. var n; Defining n = 5
29th Aug 2020, 4:19 PM
Jayakrishna 🇮🇳