Last active
February 23, 2022 15:23
-
-
Save codistwa/8ea554d0e876ca00d97decaf1ac3f508 to your computer and use it in GitHub Desktop.
Course source code: https://codistwa.com/guides/variables-and-types. More courses on https://codistwa.com
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
// ============================================================ | |
// Definition of a variable | |
// ============================================================ | |
const welcome = 'Hello'; | |
console.log(typeof(welcome)); // string | |
// ============================================================ | |
// Types | |
// ============================================================ | |
const welcome = 'Hello'; | |
let length = 2; | |
const isHidden = false; | |
// ============================================================ | |
// Concatenation | |
// ============================================================ | |
const presentation = 'I have'; | |
let age = 32; | |
console.log(presentation + ' ' + age); // I have 32 | |
console.log(`${presentation} ${age}`); // I have 32 | |
// ============================================================ | |
// Mutation | |
// ============================================================ | |
const welcome = 'Hello'; | |
let length = 2; | |
welcome = 't'; | |
length = 3; | |
console.log(welcome); // error | |
console.log(length); // no error | |
// ============================================================ | |
// Conversion | |
// ============================================================ | |
console.log('3' + 2); // 32 | |
console.log('3' - 2); // 1 | |
console.log('five' * 2); // NaN | |
// ============================================================ | |
// Scope | |
// ============================================================ | |
const doors = 5; // global | |
function getDoors() { | |
const bathrooms = 1; // local | |
console.log(doors); | |
} | |
function getBathRooms() { | |
console.log(bathroom); // error | |
} | |
console.log(getDoors()); // 5 | |
console.log(getBathRooms()); // undefined | |
// ============================================================ | |
// Naming conventions | |
// ============================================================ | |
// bad | |
const str = 'Marie'; | |
// good | |
const firstName = 'Marie'; | |
// bad | |
const zero = 0; | |
// good | |
const total = 0; | |
// bad | |
const open = true; | |
const hidden = false; | |
// good | |
const isOpen = true; | |
const isHidden = false; |
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
# ============================================================ | |
# Definition of a variable | |
# ============================================================ | |
welcome = 'Hello' | |
print(type(welcome)) # <class 'str'> | |
# ============================================================ | |
# Types | |
# ============================================================ | |
welcome = 'Hello' | |
length = 2 | |
isHidden = False | |
# ============================================================ | |
# Concatenation | |
# ============================================================ | |
presentation = 'I have' | |
age = 32 | |
print(presentation + ' ' + str(age)) # I have 32 | |
print("%s %s" % (presentation, str(age))) # I have 32 | |
# ============================================================ | |
# Mutation | |
# ============================================================ | |
length = 2 | |
length = 3 | |
print(length) # 3 | |
# ============================================================ | |
# Conversion | |
# ============================================================ | |
print('3' + str(2)) # 32 | |
print('five' * str(2)) # Error | |
# ============================================================ | |
# Scope | |
# ============================================================ | |
doors = 5 # global | |
def getDoors(): | |
bathrooms = 1 # local | |
print(doors) | |
def getBathRooms(): | |
print(bathroom) # error | |
print((getDoors())) # 5 | |
print(getBathRooms()) # None | |
# ============================================================ | |
# Naming conventions | |
# ============================================================ | |
# bad | |
str = 'Marie' | |
# good | |
first_name = 'Marie' | |
# bad | |
zero = 0 | |
# good | |
total = 0 | |
# bad | |
open = True | |
hidden = False | |
# good | |
is_open = True | |
is_hidden = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment