JavaScript
/Beginner
Operators & Comparisons
Definition
Symbols or keywords that tell the JavaScript engine to perform mathematical, relational, or logical operations.
Explain Like I'm New
Operators are the verbs of programming. If variables are the nouns (like '5' or '10'), the operators are the actions (like '+', '-', '>').
Real World Example
Using the logical AND `&&` operator to conditionally render a button: `isLoggedIn && <button>Logout</button>`.
Common Use Cases
- •Math calculations
- •Conditional logic
- •Assigning values
Terminal Output
bash / terminal
console.log('5' + 3); // '53'
console.log('5' - 3); // 2
console.log(typeof null); // 'object'
// Double tilde ~~ is a fast shorthand for Math.floor() on positive numbers
console.log(~~4.9); // 4
Interview Questions
basic
- What is the difference between `+` and `-` when used with strings?
intermediate
- What does the typeof operator return for `null`?
advanced
- How does the bitwise NOT operator `~` work and what is `~~` used for?