Last active
March 14, 2023 20:00
-
-
Save sandrabosk/2127a27c85d2b7b202b8710a8d52885a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// We use variables to store some information. We can imagine them as some kind of boxes, | |
// or storages, in which we place some data. | |
// To be able to re-access this data (to be able to reference them), we need to name them somehow. | |
// So we can say that varibles (storages) are named or we can say labeled. | |
// 3 ways to declare variables in JS: | |
// var | |
// let | |
// const | |
let student; // var. declaration (saving a spot in memory) | |
console.log("Value is: ", student); // Value is: undefined | |
student = "kevin"; // var. assignment (initialization) - giving it a value | |
let firstName = "sandra"; // declaration and initialization in the same time | |
// π¨can't name it with number starting nor with JS reserved words: | |
// let 3students π«π«π« | |
// class, let, const, function, for, ... π«π«π« | |
// multiple var. declarations | |
let price, tax, total; | |
// use camelCase (but if you want to use snake_case is OK, just be consistent) | |
let totalPrice // camelCase | |
let total_amount // snake_case | |
let name; // lowercase | |
// let Name; π«π«π« | |
// this is single line comment | |
/* this is | |
multiple lines | |
comment */ | |
// skip: | |
// numbers are immutable data types - can't change their value, you are actually creating a new variable with the same name | |
// price = 7; | |
// price = 9; | |
// double quotes combined with single quotes (string) | |
let pizza = "margarita is 'the best' "; | |
console.log(pizza); // ==> margaritha is 'the best' | |
// "const" is used when declaring a variable which value will be constant. | |
// if we try to change its values we will get the error back | |
const name = 'Ana'; | |
name = 'Marina'; | |
// console: | |
// unknown: "name" is read-only | |
// Using "let" we can only declare a variable without assigning it a value. That is not the case with "const". | |
// Variable needs to be declared and initialized at the same time. | |
let name; // <== we can do this | |
const price; // <== error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment