297
Gender.js (lemmy.world)

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;

all 40 comments
sorted by: hot top controversial new old
[-] andrew@lemmy.stuart.fun 111 points 1 year ago

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

[-] Phen@lemmy.eco.br 27 points 1 year ago

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

[-] soloner@lemmy.world 22 points 1 year ago

Reassignment isn't the same as mutation. But mutation depends on the type of value. If gender was a string like "female" it wouldn't be mutable cuz strings are immutable in JS.

[-] andrew@lemmy.stuart.fun 5 points 1 year ago

Yeah this is true. My joke makes an assumption about the type not being a primitive type.

[-] andrew@lemmy.stuart.fun 7 points 1 year ago

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.

[-] Klaymore@sh.itjust.works 6 points 1 year ago

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

[-] shotgun_crab@lemmy.world 6 points 1 year ago

Classic javascript doing javascript things (this is why they introduced let and const)

[-] CheezyWeezle@lemmy.world 3 points 1 year ago* (last edited 1 year ago)

Kind of. With hoisting, the compiler/interpreter will find variable declarations and execute them before executing the rest of the code. Hoisting leaves the variables as undefined until the code assigning the value to the variable is executed. Hoisting does not initialize the variables.

For example:

console.log(foo);
var foo;
//Expected output: console logs 'null'

foo = 'bar';
console.log(foo);
var foo;
//Expected output: console logs 'bar'

console.log(foo === undefined);
var foo;
//Expected output: console logs 'true'

This means you can essentially write your code with variable declarations at the end, but it will still be executed as though the declarations were at the beginning. Your initializations and value assignments will still be executed as normal.

This is a feature that you should probably avoid because I honestly cannot think of any good use case for it that won't end up causing confusion, but it is important to understand that every variable within your scope will be declared at the beginning of execution regardless of where it is written within your code.

[-] andrew@lemmy.stuart.fun 2 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.

[-] lseif@sopuli.xyz 4 points 1 year ago

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

[-] Baizey@feddit.dk 3 points 1 year ago

// @ts-ignore

[-] Ghyste@sh.itjust.works 65 points 1 year ago

Douchebag Peterson doesn't deserve to be a meme.

[-] lseif@sopuli.xyz 29 points 1 year ago

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

[-] nxdefiant@startrek.website 20 points 1 year ago* (last edited 1 year ago)

python:

gender: Optional[str] = None

[-] synae@lemmy.sdf.org 7 points 1 year ago

How about:

gender: Optional[complex]
[-] xthexder@l.sw0.com 7 points 1 year ago

self.gender = 1.63-2.1j 🤔

[-] Funkytom467@lemmy.world 16 points 1 year ago

Anyway you put it it's not gonna please non-binary people.

[-] IzzyScissor@lemmy.world 20 points 1 year ago

NB here - this is hilarious.

[-] flying_sheep@lemmy.ml 16 points 1 year ago* (last edited 1 year ago)
const gender = 0.5

Non-binary, cis, non-genderfluid

[-] girsaysdoom@sh.itjust.works 15 points 1 year ago
[-] CanadaPlus@lemmy.sdf.org 9 points 1 year ago
[-] QuazarOmega@lemy.lol 4 points 1 year ago* (last edited 1 year ago)

It's not a gender tho... Or is it?
vsauce music starts playing

[-] girsaysdoom@sh.itjust.works 1 points 1 year ago

Good point!

[-] CallumWells@lemmy.ml 2 points 1 year ago* (last edited 1 year ago)

Null was a mistake (as per what quite a few people say) XD

Don't know if some actual thing saying "undefined" explicitly would/could be any better, though.

[-] docAvid@midwest.social 2 points 1 year ago

There are two kinds of "null" that are often called out as mistakes, you may be thinking of. One is the null reference, as found in languages like C and Java, which Tony Hoare, who created it for ALGOL back in the sixties, has called his "billion dollar mistake". The other is the three-valued-logic of null in SQL, which is almost as bad.

There's nothing wrong with "null", necessarily, in other contexts, although I do think a more clear name for whatever it means in any given context might be better.

[-] lugal@sopuli.xyz 7 points 1 year ago* (last edited 1 year ago)

That's 0.1 ~2~ so it's still binary

Checkmate atheist

Edit: the 2 is supposed to be a subscript

[-] HumanPerson@sh.itjust.works 7 points 1 year ago

Now write it in IEEE754 without using the internet.

[-] lugal@sopuli.xyz 7 points 1 year ago

I can't comment anything without the internet. Checkmate atheist.

[-] HumanPerson@sh.itjust.works 5 points 1 year ago

I didn't say you had to write it on Lemmy. Write it on paper.

[-] lugal@sopuli.xyz 4 points 1 year ago
[-] HumanPerson@sh.itjust.works 3 points 1 year ago

The third bit is wrong. Prove me wrong.

[-] Funkytom467@lemmy.world 2 points 1 year ago

Yeah that's what i meant, well...

I guess binary is better interpreted as a boolean than being actually written in a binary base.

They forgot what it's like coding in binary i tell you that!

[-] CapeWearingAeroplane@sopuli.xyz 4 points 1 year ago

People not getting this... computers are inherently binary (until quantum computers become truly viable). That's the joke.

[-] mypasswordis1234@lemmy.world 11 points 1 year ago

Can anyone explain it to me, please? 🥹

[-] Sarsoar 29 points 1 year ago

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.

[-] docAvid@midwest.social 4 points 1 year ago

I interpret it a bit differently. After all, a variable declared with var isn't really more capable of being rebound, or bound to more values, than one declared with let. However, it is possible, with var, that setting a variable in one place could change it unexpectedly in another, so Rose Noble coming out as trans could cause Jordan Peterson to also suddenly be a woman.

[-] xigoi@lemmy.sdf.org 1 points 1 year ago

Just to be pedantic, const declares an immutable variable, not a constant.

this post was submitted on 29 Dec 2023
297 points (100.0% liked)

Programmer Humor

34912 readers
121 users here now

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

Rules:

founded 5 years ago
MODERATORS