this post was submitted on 29 Dec 2023
57 points (85.2% liked)

Programmer Humor

32730 readers
91 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

cross-posted from: https://lemmy.world/post/10094818

spoilerGender variability as declarations in JavaScript: const / let / var

Meme is based on Jordan Peterson "approival / disapproval" format, him being a conservative who disapproves of gender fluidity.

Transcript:

  • Jordan Peterson approval image: const gender;
  • Jordan Peterson angry image: let gender;
  • Jordan Peterson crying image: var gender;

top 16 comments
sorted by: hot top controversial new old
[–] [email protected] 23 points 1 year ago (2 children)

Joke's on you because they're all still mutable objects behind the reference.

[–] [email protected] 6 points 1 year ago (1 children)

Last one can be freely changed by anyone, the middle one still has some restraints.

[–] [email protected] 1 points 1 year ago (1 children)

var isn't global unless it's not inside a function. var is just function scoped, with declaration auto hoisted to the beginning of the function. let is a little more intuitive since you can't refer to it before it's been declared and has block scope rather than function scope.

[–] [email protected] 0 points 1 year ago (1 children)

Wait...... you can use a variable before you declare it?

[–] [email protected] 0 points 1 year ago* (last edited 1 year ago)
var a;
(function() {
  a='hoisted';
  console.log(a);
  var a;
})()
console.log(a);

Should log hoisted and then undefined, showing that you've assigned to the later-declared var a which was hoisted vs the external global a.

[–] [email protected] 1 points 1 year ago (1 children)

typescript: const as const (readonly) 'pretty please dont mutate it'

[–] [email protected] 1 points 1 year ago

// @ts-ignore

[–] [email protected] 19 points 1 year ago

Douchebag Peterson doesn't deserve to be a meme.

[–] [email protected] 12 points 1 year ago

void* gender it can be anything i want >:)

[–] [email protected] 5 points 1 year ago* (last edited 1 year ago) (1 children)

python:

gender: Optional[str] = None

[–] [email protected] 3 points 1 year ago (1 children)

How about:

gender: Optional[complex]
[–] [email protected] 3 points 1 year ago

self.gender = 1.63-2.1j 🤔

[–] [email protected] 0 points 1 year ago (1 children)

Can anyone explain it to me, please? 🥹

[–] [email protected] 0 points 1 year ago (1 children)

In JavaScript, a const variable is an immutable constant that you cannot reassign. Similar to how many conservatives think of gender, an intrinsic fact of a person that you can only read, but never change.

The "let" keyword declares a variable in a local scope, the nearest surrounding curly braces. It can be changed in that scope, but does not exist anywhere else. I assume this is meant to concede that gender is a spectrum and your presentation can kind of wiggle, such as between "very manly" and "not as manly" but still a man. Like, a stereotypical lumberjack and a stereotypical twink are both men so there isn't "one way to be a man" but a conservative might say " but they are still men, you can change how you present but you can't change sex".

The "var" keyword lifts the variable definition to the top of the function, or "hoists" it up. A variable declared with var can be accessed and modified anywhere after the block it was declared in. Gender is a spectrum and it can be reassigned anywhere, at anytime, to anything.

[–] [email protected] 0 points 1 year ago (1 children)

The "var" keyword lifts the variable definition to the top of the function, or "hoists" it up. A variable declared with var can be accessed and modified anywhere after the block it was declared in. Gender is a spectrum and it can be reassigned anywhere, at anytime, to anything.

similar to how most liberals think of gender

[–] [email protected] 0 points 1 year ago

I thought this was obvious.