Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
/
^Q: ((?:.*|\n)*?)\n*A: (.+(?:\n(?:^.{1,3}$|^.{4}(?<!<!--).*))*)
/
gm
Input 1
1
New
Q: diff between null and undefined? A: Null indicates an intentional empty value. - Undefined indicates the total absence of a value. This happen when only the variable was declared without any initializer. A missing key in an object is also undefined. ```javascript export function ticketStatus(tickets, ticketId) { if (tickets[ticketId] === undefined) { return 'unknown ticket id'; } else if (tickets[ticketId] === null) { return 'not sold'; } else { return `sold to ${tickets[ticketId]}`; } } ``` <!--ID: 1673953179724--> --- Q: rewrite to use [[JS Object.assign]] ```javascript visitor.ticketId = null; return visitor; ``` A: Just pass only the props we want to overwrite to assign ```javascript return Object.assign(visitor, {ticketId: null}); ``` <!--ID: 1673953179746--> --- Q: diff between isNaN() global vs Number.isNaN()? A: global isNaN() does type conversion. - Since I am trying to test whether the string contains a valid number, this is the right choice. - If the input is already a number, then Number.isNaN() might be better. as ---
Substitution
Q: diff between null and undefined? A: Null indicates an intentional empty value. - Undefined indicates the total absence of a value. This happen when only the variable was declared without any initializer. A missing key in an object is also undefined. ```javascript export function ticketStatus(tickets, ticketId) { if (tickets[ticketId] === undefined) { return 'unknown ticket id'; } else if (tickets[ticketId] === null) { return 'not sold'; } else { return `sold to ${tickets[ticketId]}`; } } ``` <!--ID: 1673953179724--> --- Q: rewrite to use [[JS Object.assign]] ```javascript visitor.ticketId = null; return visitor; ``` A: Just pass only the props we want to overwrite to assign ```javascript return Object.assign(visitor, {ticketId: null}); ``` <!--ID: 1673953179746--> --- Q: diff between isNaN() global vs Number.isNaN()? A: global isNaN() does type conversion. - Since I am trying to test whether the string contains a valid number, this is the right choice. - If the input is already a number, then Number.isNaN() might be better. as ---