We hold data in variables. Variable is used as a container for our data. Think about holding a name.
- var is shortcut for variable. It is not a must but makes code readble. We can ommit the var while writing code
- name is the name of the variable when we need to access the data we will use name
- = assigns “Poftut” to the name variable
As developing applications there will be a lot of different data to work. From numbers to logic true,false. We need to use some types to define our data.
Say we develop a calculator. We want to add numbers we can write a code like below.
Or expressing logic values like True, False is different from text values.
We will look details of this types next chapters.
Scope means a variable use able area. For example we can not use variables declared other than current file or we can not access a varibale defined outside of function
- Local Variable is only accessable from its scope
- Global Variable is access able from anywhere
As we see a function creates its own scope and variables created in this local scope can not be accessed from global scope
Variable names can use different characters but there is some limitations.
- Variable names can not start with numbers. Which means
- 12name is not valid variable name
- name12 is valid variable name