|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +permalink: /logs/2025-11-12/ |
| 4 | +--- |
| 5 | + |
| 6 | +# Devlog - 2025-11-12 |
| 7 | + |
| 8 | +## 🚀 What I Did |
| 9 | + |
| 10 | +- Some lab work on boolean and numbers. |
| 11 | + |
| 12 | +## 🧠 What I Learned |
| 13 | + |
| 14 | +### Objects in JS |
| 15 | + |
| 16 | +```javascript |
| 17 | +const exampleObject = { |
| 18 | + propertyName: value; |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +- To access most common is dot notation `objectName.propertyName`. |
| 23 | + |
| 24 | +```javascript |
| 25 | +// bracket notation |
| 26 | +const person = { |
| 27 | + name: "Alice", |
| 28 | + age: 30, |
| 29 | + city: "New York" |
| 30 | +}; |
| 31 | + |
| 32 | +console.log(person["name"]); // Alice |
| 33 | +console.log(person["age"]); // 30 |
| 34 | +``` |
| 35 | + |
| 36 | +- Functions and object methods are both ways to encapsulate reusable code. |
| 37 | +- `Object()` - when you want to create an object wrapper for a primitive value. |
| 38 | +- Recipe Tracker. |
| 39 | + |
| 40 | +### JSON |
| 41 | + |
| 42 | +- `JSON` - javascript object notation. |
| 43 | +- Is a lightweight data format used for data exchange between servers and web applications. |
| 44 | + |
| 45 | +```javascript |
| 46 | +{ |
| 47 | + "name": "Alice", |
| 48 | + "age": 30, |
| 49 | + "isStudent": false, |
| 50 | + "list of courses": ["Mathematics", "Physics", "Computer Science"] |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +- `JSON.stringify()` is used to convert a JavaScript object into a JSON string. |
| 55 | + |
| 56 | +```javascript |
| 57 | +const developerObj = { |
| 58 | + firstName: "Jessica", |
| 59 | + isAwesome: true, |
| 60 | + isMusician: true, |
| 61 | + country: "USA", |
| 62 | +}; |
| 63 | + |
| 64 | +// result: {"firstName":"Jessica","country":"USA"} |
| 65 | +console.log(JSON.stringify(developerObj, ["firstName", "country"])); |
| 66 | +``` |
| 67 | + |
| 68 | +- Also accepts an optional parameter called a `replacer`, which can be a function or an array. |
| 69 | +- `JSON.parse()` converts a JSON string back into a JavaScript object. |
| 70 | + |
| 71 | +```javascript |
| 72 | +const jsonString = '{"name":"John","age":30,"isAdmin":true}'; |
| 73 | +const userObject = JSON.parse(jsonString); |
| 74 | +console.log(userObject); |
| 75 | + |
| 76 | +// Result: |
| 77 | +// { name: 'John', age: 30, isAdmin: true } |
| 78 | +``` |
| 79 | + |
| 80 | +- Optional chaining operator - `?.` is a useful tool in JavaScript that lets you safely access object properties or call methods without worrying whether they exist. |
| 81 | + |
| 82 | +## 🔥 What's Next |
| 83 | + |
| 84 | +- Objects. |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +[← Previous]({{site.baseurl}}/logs/2025-11-10/) |
0 commit comments