Ours might be a love story.
I promise I don't mean it. But maybe we see where this story ends.
I installed code runner on my VS Code. You might want to know why. The code runner is a popular VS code extension that allows the running of code directly in the editor. It allows running multiple programming languages on the VS code e.g. Python, Java, Javascript, Powershell, amongst others. With it, one can run code without having to open a separate terminal.
Then I learnt Variables in Javascript. They are summarised as follows.
- Variables are containers for storing temporary data in Javascript.
- when you have data in a variable you can use it multiple times. E.g.
let num = 2 + 2
console.log(4 + num)
- You don't always have to create an operation to assign a value, you can also directly assign the value.
let num = 4
console.log(num)
num = 9
console.log(num)
- Every time you want to assign a string or text to your code, always use a double quote or quote. e.g.
let username = 'Aisha'
console.log(username).
However, the problem with using only quotes is that in case there are future needs to use apostrophes, it might lead to errors, e.g. let username = 'Aisha's bag' - Error.
let username= ''Aisha' bag" - Correct
- You can also change variables e.g.
let radius = 5
let pi = 3.14 (note: pi is constant, the value doesn't change. This is just for the purpose of explanation)
let area
let radius= 6
let pi = 5
area = pi * radius * radius
console.log(area)
- Do not declare a variable multiple times. It will lead to errors.
- A variable name can have characters, numbers and special symbols (only Underscore and the dollar symbol are allowed!). Numbers are allowed but not as a first character. Also, Names are case-sensitive. Spaces aren't allowed as well.
- For readability of variables, you can use underscores (for names with two words). E.g. let user_name = 'Aisha'. This is called the SNAKE CASING rule. You can also make the second word's first letter begin with a capital letter, e.g. let userName = 'Aisha'. This is the CAMEL CASING rule. It happens when you want to declare the variable name and there are multiple words in one name. Hence, you convert all the new words' first letter to capital letter case.
Constant (variable) - sounds like a tautology. Some call it only constant. But it is a form of variable that doesn't change. For instance, the value of pi is always constant, and once you initiate this value, it doesn't change, so instead of using let, make pi = constant. E.g. const pi = 3.14.
See you next time!