728x90 반응형 SMALL programming375 chapter 5) Troubleshooting Using Immediately Called Functions ### Breakdown of the JavaScript Code #### First `` Tag - A variable `pi` is declared using `let` with a value of `3.14`. This variable has a script-wide scope (global to the script block in which it is declared). - `console.log(`pi = ${pi}`)` then logs this value to the console, resulting in the output: `pi = 3.14`. #### Second `` Tag - An IIFE `(function () { ... })()` is defined and executed i.. 2024. 12. 5. chapter 5) use to remaining parameters make array ### Rest Parameters #### Basic Use of Rest Parameters - **Function `sample`** uses rest parameters (`...items`) to collect all passed arguments into an array named `items`. - When `sample(1,2,3)` and `sample(1,2,3,4)` are called, the function logs the `items` array to the console, showing that all provided arguments are gathered into an array. This demonstrates the flexibility of rest parameters.. 2024. 12. 4. chapter 5) arguments ### Script Breakdown - **Function Definition**: The `sample` function is defined without any formal parameters. Inside the function: - `console.log(arguments)` logs the entire `arguments` object to the console, showing all arguments passed to the function. - A `for` loop iterates over the `arguments` object using its `length` property to access each argument by index. - Inside the loop, `console.. 2024. 12. 3. chapter 4) for ### `for...in` Loop - Iterates over the indices (keys) of the `todos` array. - Logs the index and corresponding value of each element in the array. - Example output: `0 : buy milk`, indicating that `0` is the index and `buy milk` is the value at that index. - Note: While `for...in` loops can iterate over array indices, they are generally not recommended for arrays because they iterate over all e.. 2024. 12. 2. 이전 1 ··· 14 15 16 17 18 19 20 ··· 94 다음 728x90 반응형 LIST