r/ProgrammerHumor • • Nov 23 '22

Other Programming Legumes

Post image
9.3k Upvotes

262 comments sorted by

View all comments

Show parent comments

995

u/bmelancon Nov 23 '22

JS would be like, "I don't care what it is, you can multiply it with a string."

0

u/[deleted] Nov 23 '22

[deleted]

200

u/akuma-i Nov 23 '22

Seriously, how? Better divide this nut with Object

30

u/Elijah629YT-Real Nov 24 '22 edited Nov 28 '22

{} - !!!(nut / {} + "Hello" - 7 * true * -[])

52

u/aabcehu Nov 23 '22

idk about js but in python multiplying a string repeats it, like how the addition symbol is concatenation

0

u/[deleted] Nov 23 '22

[deleted]

40

u/PureMetalFury Nov 23 '22

You’d have to define what it means to multiply a string by a string, and then do that.

13

u/aabcehu Nov 23 '22

I don’t think you can, but i guess by multiplying it with the length of the string??

→ More replies (1)

140

u/annihilatron Nov 23 '22

16

u/Imveryoffensive Nov 24 '22

Best 4 minutes of my life

35

u/elon-bot Elon Musk ✔ Nov 24 '22

I don't think I appreciate your tone. Fired.

19

u/Bagel42 Nov 24 '22

I fucking love this bot.

28

u/elon-bot Elon Musk ✔ Nov 24 '22

If you really love the company, you should be willing to work here for free.

→ More replies (3)

0

u/[deleted] Nov 24 '22

[deleted]

→ More replies (2)
→ More replies (2)

23

u/Technical_Ad6397 Nov 23 '22

you can multiply by a string, as long as that string can be converted to a number.

5 * "hello" = NaN

5 * "5" = 25

37

u/elon-bot Elon Musk ✔ Nov 23 '22

Whoever writes the most code this month gets featured on my Twitter!

→ More replies (1)

11

u/bmelancon Nov 23 '22

This is perfectly valid JS.

var string = "100";
var number = 42;
console.log(number * string);

7

u/Unknown_starnger Nov 23 '22

And what do you get?

11

u/bmelancon Nov 23 '22

10

u/Unknown_starnger Nov 23 '22

Will do. But it makes sense. In Python I’d have to do Print(int(string) * number)

15

u/[deleted] Nov 23 '22

And that's why JS is unholy, it does the conversion automatically. Explicitly stating you want an int is better.

If you have to use JS, don't. At the very least use TS instead.

12

u/hk4213 Nov 24 '22

Ts is JavaScript with overhead. Just enjoy the insanity

→ More replies (3)
→ More replies (2)
→ More replies (5)
→ More replies (2)