Task 3: Type casting
What will be printed to the console? Explain why.
✅ Write your version in the comments 📝
🔎 Look for a hint:
1. "53" (concatenation, since "5" is a string)
2. "2" (the string "5" is converted to a number)
3. "6" (true is converted to 1)
4. "20" (both values are converted to numbers)
5. "NaN" (you can't subtract a number from a string of letters)
6. "5" (null is converted to 0)
7. "NaN" (undefined can't be a number)
8. "true" (a non-empty string is truthy)
9. "false" (0 is falsy)
10. "true" (an array is a truthy value)
Explanation:
JS automatically converts strings and numbers in arithmetic operations.
null becomes 0, undefined becomes NaN.
!! is a double logical negation that turns a value into true or false.
What will be printed to the console? Explain why.
console.log("5" + 3);
console.log("5" - 3);
console.log(5 + true);
console.log("10" * "2");
console.log("10px" - 2);
console.log(null + 5);
console.log(undefined + 5);
console.log(!!"false");
console.log(!!0);
console.log(Boolean([])); ✅ Write your version in the comments 📝
🔎 Look for a hint:
2. "2" (the string "5" is converted to a number)
3. "6" (true is converted to 1)
4. "20" (both values are converted to numbers)
5. "NaN" (you can't subtract a number from a string of letters)
6. "5" (null is converted to 0)
7. "NaN" (undefined can't be a number)
8. "true" (a non-empty string is truthy)
9. "false" (0 is falsy)
10. "true" (an array is a truthy value)
Explanation:
JS automatically converts strings and numbers in arithmetic operations.
null becomes 0, undefined becomes NaN.
!! is a double logical negation that turns a value into true or false.
👍7❤4
Сhoose the correct option
Anonymous Quiz
55%
"53", 2, 6, 20, NaN, 5, NaN, true, false, true
33%
"53", 2, 5, 102, NaN, 5, undefined , true, false, false
12%
8, 2, 6, 20, NaN, 5, undefined , true, true, true
Task 4: Using let, const, var
What will be the result of running the code? Why?
✅ Сhoose the correct option 📝
🔎 Look for a hint:
1. undefined (due to hoisting, variable is declared but not yet initialized)
2. Error! Variable is declared but is in the "dead zone" (TDZ)
3. 50 (var variable is accessible outside the block)
4. Error! y is only defined in the if block
Explanation:
var is hoisted but not initialized, so console.log(a); prints undefined.
let and const are not hoisted, so console.log(b); throws an error.
var is not block scoped, so x is accessible outside the block.
let is scoped to {} and y is not accessible outside the if block.
What will be the result of running the code? Why?
console.log(a);
var a = 10;
console.log(b);
let b = 20;
if (true) {
var x = 50;
}
console.log(x);
if (true) {
let y = 60;
}
console.log(y);
✅ Сhoose the correct option 📝
🔎 Look for a hint:
2. Error! Variable is declared but is in the "dead zone" (TDZ)
3. 50 (var variable is accessible outside the block)
4. Error! y is only defined in the if block
Explanation:
var is hoisted but not initialized, so console.log(a); prints undefined.
let and const are not hoisted, so console.log(b); throws an error.
var is not block scoped, so x is accessible outside the block.
let is scoped to {} and y is not accessible outside the if block.
👍6🔥6
Сhoose the correct option
Anonymous Quiz
22%
10, 20, 50, Error
51%
undefined, Error, 50, Error
27%
10, Error, 50, 60
Task 5: Determine the result of the code
What will be the result of executing the following code? Why?|
✅ Сhoose the correct option 📝
🔎 Look for a hint:
1. 2 (bar and foo point to the same object)
2. [1, 2, 3, 4] (a and b point to the same array)
3. "hello" (strings are primitives, passed by value)
Explanation:
Objects and arrays are passed by reference, so bar.n changes foo.n, and b.push(4) changes a.
Primitive types (string, number, boolean) are passed by value, so changing y does not affect x.
What will be the result of executing the following code? Why?|
let foo = { n: 1 };
let bar = foo;
bar.n = 2;
console.log(foo.n);
let a = [1, 2, 3];
let b = a;
b.push(4);
console.log(a);
let x = "hello";
let y = x;
y = "world";
console.log(x);✅ Сhoose the correct option 📝
🔎 Look for a hint:
2. [1, 2, 3, 4] (a and b point to the same array)
3. "hello" (strings are primitives, passed by value)
Explanation:
Objects and arrays are passed by reference, so bar.n changes foo.n, and b.push(4) changes a.
Primitive types (string, number, boolean) are passed by value, so changing y does not affect x.
❤6🔥1
✅ Сhoose the correct option 📝
Anonymous Quiz
41%
2, [1, 2, 3, 4], "hello"
37%
1, [1, 2, 3], "hello"
23%
2, [1, 2, 3, 4], "world"
🔎 CSS content-visibility: The Web Performance Boost You Might Be Missing
The content-visibility CSS property delays rendering an element, including layout and painting, until it is needed
Web performance optimization can be a real headache. Shaving off milliseconds here and there, minifying everything in sight, and praying to the performance gods.
The content-visibility CSS property delays rendering an element, including layout and painting, until it is needed
Web performance optimization can be a real headache. Shaving off milliseconds here and there, minifying everything in sight, and praying to the performance gods.
❤6👍2🔥1
⏰ Master JavaScript date and time: From Moment.js to Temporal
JavaScript’s Date API has long been a source of frustration for developers due to its historical design flaws, including its:
- Unreliable parsing behavior
- Mutable nature
- Weak time zone support
To overcome these issues and limitations, developers have turned to libraries like Moment.js for more reliable and feature-rich date and time handling. Now, JavaScript has a new built-in solution on the horizon: the Temporal API, which brings a modern and intuitive approach to date and time manipulation.
In this article, we’ll examine JavaScript’s Date API limitations, discussing the strengths and weaknesses of popular libraries like Moment.js, and delving into the Temporal API.
JavaScript’s Date API has long been a source of frustration for developers due to its historical design flaws, including its:
- Unreliable parsing behavior
- Mutable nature
- Weak time zone support
To overcome these issues and limitations, developers have turned to libraries like Moment.js for more reliable and feature-rich date and time handling. Now, JavaScript has a new built-in solution on the horizon: the Temporal API, which brings a modern and intuitive approach to date and time manipulation.
In this article, we’ll examine JavaScript’s Date API limitations, discussing the strengths and weaknesses of popular libraries like Moment.js, and delving into the Temporal API.
👍7❤2
🔥 Lesson 2: Operators and Control Flow in JavaScript!
What will you learn in this lesson?
✅ How arithmetic, logical, and bitwise operators work
✅ How to use conditions (if, switch) and loops (for, while, do...while)
✅ The power of break, continue, and the ternary operator
✅ Common mistakes and best practices to write cleaner code
By the end of this lesson, you'll be able to control program logic and write more efficient code with confidence! 🚀
🔗 Read the article and practice your skills! 💡
#js_course #js_lesson_2
What will you learn in this lesson?
✅ How arithmetic, logical, and bitwise operators work
✅ How to use conditions (if, switch) and loops (for, while, do...while)
✅ The power of break, continue, and the ternary operator
✅ Common mistakes and best practices to write cleaner code
By the end of this lesson, you'll be able to control program logic and write more efficient code with confidence! 🚀
🔗 Read the article and practice your skills! 💡
#js_course #js_lesson_2
🔥5👍4
Task 1: Even or odd?
Write a function isEven that takes a number and returns "Even" if the number is even and "Odd" if it is odd.
✅ Сhoose the correct option ✅ Or write your version in the comments 📝
1️⃣
2️⃣
3️⃣
Write a function isEven that takes a number and returns "Even" if the number is even and "Odd" if it is odd.
console.log(isEven(4)); // "Even"
console.log(isEven(7)); // "Odd"
✅ Сhoose the correct option ✅ Or write your version in the comments 📝
1️⃣
function isEven() {
return num % 2 === 0 ? "Even" : "Odd";
}2️⃣
function isEven(num) {
return num % 2 = 0 ? "Even" : "Odd";
}3️⃣
function isEven(num) {
return num % 2 === 0 ? "Even" : "Odd";
}👍5❤3
One of Those “Onboarding” UIs, With Anchor Positioning
Anchor positioning lets us attach — or “anchor” — one element to one or more other elements. More than that, it allows us to define how a “target” element (that’s what we call the element we’re attaching to an anchor element) is positioned next to the anchor-positioned element, including fallback positioning in the form of a new @position-try at-rule.
Anchor positioning lets us attach — or “anchor” — one element to one or more other elements. More than that, it allows us to define how a “target” element (that’s what we call the element we’re attaching to an anchor element) is positioned next to the anchor-positioned element, including fallback positioning in the form of a new @position-try at-rule.
👍6❤1
Task 2: Find the maximum of three numbers
Write a function findMax that takes three numbers and returns the largest of them.
✅ Сhoose the correct option ✅ Or write your version in the comments 📝
1️⃣
2️⃣
3️⃣
Write a function findMax that takes three numbers and returns the largest of them.
console.log(findMax(5, 12, 9)); // 12
✅ Сhoose the correct option ✅ Or write your version in the comments 📝
1️⃣
function findMax(a, b, c) {
return Math.max(a, b, c);
}2️⃣
function findMax() {
return Math.max(a, b, c);
}3️⃣
function findMax(a, b, c) {
Math.max(a, b, c);
}👍3❤1
🧐 You probably don’t need http-equiv meta tags
Until recently, I just assumed you could put anything equivalent to an HTTP header in an http-equiv meta tag, and browsers would treat it like the header itself. Maybe you thought the same thing—why wouldn’t you, with a name like that.
But as it turns out, there are actually very few standard values that you can set here. And some values don’t even behave the same way as their header equivalents! What’s going on here and how are we supposed to use this thing?
Until recently, I just assumed you could put anything equivalent to an HTTP header in an http-equiv meta tag, and browsers would treat it like the header itself. Maybe you thought the same thing—why wouldn’t you, with a name like that.
But as it turns out, there are actually very few standard values that you can set here. And some values don’t even behave the same way as their header equivalents! What’s going on here and how are we supposed to use this thing?
👍4❤1
🧑💻 Task 3: Fizz-Buzz
Write a program that prints numbers from 1 to 20, but:
If the number is divisible by 3, print "Fizz"
If the number is divisible by 5, print "Buzz"
If the number is divisible by both 3 and 5, print "FizzBuzz"
Otherwise, just print the number
Example output:
✅ Сhoose the correct option ✅ Or write your version in the comments 📝
1️⃣
2️⃣
3️⃣
Write a program that prints numbers from 1 to 20, but:
If the number is divisible by 3, print "Fizz"
If the number is divisible by 5, print "Buzz"
If the number is divisible by both 3 and 5, print "FizzBuzz"
Otherwise, just print the number
Example output:
// 1 2 Fizz 4 Buzz Fizz 7 ... FizzBuzz
✅ Сhoose the correct option ✅ Or write your version in the comments 📝
1️⃣
for (let i = 1; i <= 20; i++) {
if (i % 3 = 0 && i % 5 = 0) {
console.log("FizzBuzz");
} else if (i % 3 = 0) {
console.log("Fizz");
} else if (i % 5 = 0) {
console.log("Buzz");
} else {
console.log(i);
}
}2️⃣
for (let i = 1; i <= 20; i++) {
if (i % 3 === 0 && i % 5 === 0) {
console.log("FizzBuzz");
} else if (i % 3 === 0) {
console.log("Fizz");
} else if (i % 5 === 0) {
console.log("Buzz");
} else {
console.log(i);
}
}3️⃣
for (let i = 1; i <= 20; i++) {
if (i % 3 === 0 || i % 5 === 0) {
console.log("FizzBuzz");
} else if (i % 3 === 0) {
console.log("Fizz");
} else if (i % 5 === 0) {
console.log("Buzz");
} else {
console.log(i);
}
}👍2❤1🔥1
👍6
🧑💻 Task 4: Countdown with while
Write a function countdown that takes a number n and prints a countdown to 1 to the console.
✅ Сhoose the correct option ✅ Or write your version in the comments 📝
1️⃣
2️⃣
3️⃣
Write a function countdown that takes a number n and prints a countdown to 1 to the console.
countdown(5);
// 5 4 3 2 1
✅ Сhoose the correct option ✅ Or write your version in the comments 📝
1️⃣
function countdown(n) {
while (n > 0) {
console.log(n);
}
}2️⃣
function countdown(n) {
while (n > 0) {
console.log(n);
n--;
}
}3️⃣
function countdown(n) {
while (n != 0) {
console.log(n);
n--;
}
}👍1