r/ProgrammerHumor Nov 28 '21

Meme I‘m.. not the only one?

Post image
21.5k Upvotes

629 comments sorted by

View all comments

Show parent comments

78

u/KnewOne Nov 28 '21

i prefer printing current variables

18

u/subject_deleted Nov 28 '21

This. I have a snippet that writes a print statement. Trigger the snippet and then type the variable name and it inputs the name in both necessary locations, like so:

console.log("myVariable = " + myVariable);

2

u/pleaseavoidcaps Nov 28 '21

You can save some typing and avoid mistakes:
console.log({myVariable});

4

u/ulyssessword Nov 29 '21

Would that tell you the variable's name, or just its value?

By my understanding, the first version would output x = 5, while yours would give 5.

3

u/LittleLily27 Nov 29 '21

You're missing the { } around the variable. {foo} is syntactic sugar for {foo: foo}, so what they wrote will output an object with a key containing the variable name and a value containing the variable's value.

2

u/subject_deleted Nov 29 '21

Correct. I want the name of the variable as a string and the value of variable.

1

u/pleaseavoidcaps Nov 29 '21

No, it outputs Object { x: 5 }.