Skip to main content

JS Syntax Reference (vs Python)

Ternary Operator

// JavaScript
let desc = format === 'csv' ? fileName : '';
// condition ? true value : false value

// Python
desc = file_name if format == 'csv' else ''

=== vs ==

OperatorBehaviorRecommendation
=== (strict)Type AND value must matchJS convention — almost always use this
== (loose)Auto-converts type before comparingAvoid — easy to hit unexpected behavior
1 === '1' // false (different types)
1 == '1' // true ('1' is coerced to number)
0 == '' // true 😱
0 == false // true 😱

Python's == doesn't auto-coerce types — this problem doesn't exist there.

null vs undefined

nullundefined
MeaningIntentionally set to "no value"Undeclared / no value assigned
Python analogyNoneVariable simply doesn't exist

Commonly used as placeholders so positional arguments don't get misaligned:

sendRequest(command, userId, null, path, body, undefined);
// ^^^^ ^^^^^^^^^
// auth not needed callback not needed