본문 바로가기

Programming

(69)
In Python, variable types are dynamic ✅ You don’t need to declare the type, and✅ You can change the type of a variable just by assigning a new value. In Python, variable types are dynamic, which means:✅ You don’t need to declare the type, and✅ You can change the type of a variable just by assigning a new value.🔍 Example:x = 10 # x is an intprint(type(x)) # x = "hello" # now x is a strprint(type(x)) # x = [1, 2, 3] ..
type() function To check the type of a variable in Python, you use the type() function.x = 42print(type(x)) # ➜ x = "hello"print(type(x)) # ➜ x = [1, 2, 3]print(type(x)) # ➜  // type(variable), , , etc.
Primitives vs. Objects in Practice let firstName = 'Sunjeong'; let oldFirstName = firstName; firstName = 'Sunny'; console.log(firstName, oldFirstName); // Sunny Sunjeong const sunny = { firstName: 'Sunny', lastName: 'Ryu', age: 35, }; const marriedSunny = sunny; marriedSunny.lastName = 'Y'; console.log('Before marriage: ', sunny); // Before marriage: {firstName: 'Sunny', lastName: 'Y', age: 35} console.log('After marriage: ', mar..
Primitives vs. Objects (Primitive vs. Reference Types) REVIEW: PRIMITIVES, OBJECTS AND THE JAVASCRIPT ENGINE PRIMITIVES
Regular Functions vs. Arrow Functions const sunny = { firstName: 'Sunny', year: 1988, calcAge: function () { console.log(this); console.log(2022 - this.year); }, greet: () => console.log(`Hey ${this.firstName}`), // this arrow function does not have its own this keyword. }; sunny.greet(); // Hey undefined Arrow function does not get its own this keyword It will simply use this keyword from its surroundings = its parent's this keywor..
The this Keyword EXECUTION CONTEXT - Variable environment - Scope chain - this keyword - this keyword/variable: Special variable that is created for every execution context (every function). Takes the value of (points to) the "owner" of the function in which the this keyword is used. - this is NOT static. It depends on how the function is called, and its value is only assigned when the function is actually calle..
The this Keyword in Practice console.log(this); // Window {window: Window, self: Window, document: document, name: '', location: Location, …} const calcAge = function (birthYear) { console.log(2022 - birthYear); // 34 console.log(this); // undefined }; calcAge(1988); const calcAgeArrow = birthYear => { console.log(2022 - birthYear); // 34 console.log(this); // Window {window: Window, self: Window, document: document, name: ..
Variable Environment: Hoisting and The TDZ EXECUTION CONTEXT - Variable environment - Scope chain - this keyword Hoisting: Makes some types of variables accessible/usable in the code before they are actually declared. Variables lifted to the top of their scope. Behind the scenes Before execution, code is scanned for variable declarations, and for each variable, a new property is created in the variable environment object. HOISTED INITIAL..
Hoisting and The TDZ in Practice // Variables console.log(me); // undefined console.log(job); // Uncaught ReferenceError: Cannot access 'job' before initialization console.log(year); // Uncaught ReferenceError: Cannot access 'year' before initialization var me = 'Sunny'; let job = 'technical writer'; const year = 1988; // Functions console.log(addDecl(2, 3)); // 5 console.log(addExpr(2, 3)); // Uncaught ReferenceError: Cannot a..
Scoping in Practice function calcAge(birthYear) { const age = 2022 - birthYear; function printAge() { const output = `You are ${age}, born in ${birthYear}`; console.log(output); // You are 34, born in 1988 console.log(firstName); // Sunny } printAge(); return age; } const firstName = 'Sunny'; calcAge(1988); console.log(age); // Uncaught ReferenceError: age is not defined at script.js:18:13 내부에서 외부로 접속하는 건 가능 e.g. f..