Войдите или зарегистрируйтесь
Вы сможете писать комментарии и посты, ставить лайки и другое
Поиск
Тёмная тема

Misleading naming in JavaScript: atob() and btoa()

JavaScript has two globally available metods for working with Base64: atob() and btoa(). Their names clearly look like they were borrowed from older languages. In C, for instance, the standard library includes functions like atoi and atof:

#include <stdlib.h>

char str[] = "123";
int num = atoi(str); // 123

atoi means ASCII to integer, and atof means ASCII to float (though in reality it returns a double).

So what do you think the atob function does in JavaScript? ASCII to Base64? In other words, converting a regular string into a Base64 string? Nope! It does the exact opposite: it converts a Base64 string into a "regular" string. And btoa, in turn, converts a regular string into Base64!

console.log(btoa('Famabara')); // 'RmFtYWJhcmE='
console.log(atob('RmFtYWJhcmE')); // 'Famabara'

Who thought it was a good idea to swap the names like that? Love JS.
+1
32

Perfect Homemade Chicken Broth

For years, I avoided clear broths. Childhood memories told me they were bland and only meant for sick days. Then I tried this recipe — and everything changed.
It’s crystal clear, gently aromatic, and full of flavor.
Ingredients

1 chicken breast, skin on

2 liters (about 8 cups) water

3 allspice berries

3 whole black peppercorns

2 sprigs fresh parsley

½ tablespoon salt, level
Показать полностью...
+5
25

Selfish tourists hog loungers with towels and don’t use them

I'm staying with my family at a five-star all-inclusive in Belek - not a cheap place. Around 8 or 9 in the morning we head straight to the sea for a swim, skipping the pool. By that time, the poolside loungers already look like this:
Показать полностью...
+4
18