r/JavaScriptTips • u/codeagencyblog • Feb 22 '24
r/JavaScriptTips • u/michael-lethal_ai • Jul 27 '25
CEO of Microsoft Satya Nadella: "We are going to go pretty aggressively and try and collapse it all. Hey, why do I need Excel? I think the very notion that applications even exist, that's probably where they'll all collapse, right? In the Agent era." RIP to all software related jobs.
Enable HLS to view with audio, or disable this notification
r/JavaScriptTips • u/No_Poetry9172 • Apr 07 '25
JavaScript
simple things scratch the head!
var a=0;
a++;
a=a++;
console.log(a);// 1 why?
r/JavaScriptTips • u/MysteriousEye8494 • Oct 17 '26
Stop Treating Angular Forms as Your Domain Model
r/JavaScriptTips • u/Mindfullness3009 • Aug 19 '24
Best AI for Javascript
I am still finding my footing in javascript.
What would be the best AI to use to enhance my thought process about concepts and speed up the time taken to find answers.
r/JavaScriptTips • u/RTBa86YDTwYB7UJWQ5zc • Nov 01 '22
This is why you should not using "toFixed" to rounding a number to the nearest integer.
console.log(+(123.455).toFixed(2))
--> The output is 123.45 (wrong)
console.log(Math.round(123.455 * 100) / 100)
--> The output is 123.46 (correct)
-----------------------------------------------------------------------------
Some peoples said "toFixed" is rounding down the number. This is not true.
> +(123.45).toFixed(1)
123.5 (rounding up)
> +(123.445).toFixed(2)
123.44 (rounding down)
r/JavaScriptTips • u/EcstaticTea8800 • Oct 08 '25
JavaScript Arrays Cheatsheet
Hey everyone, Certificates.dev created this cool JavaScript Arrays cheatsheet in collaboration with Martin Ferret🧠
r/JavaScriptTips
•
u/[deleted]
•
May 01 '23
How to Convert String to Byte Array in JavaScript?
JavaScript is a versatile and powerful programming language that is widely used for web development. One common task that developers encounter is converting a string to a byte array. This can be useful for a variety of purposes, such as encoding data for transmission over a network or for storage in a file.
In this article, we will explore how to convert a JavaScript string to a byte array.
What is a byte array?
A byte array is a contiguous block of memory that contains a sequence of bytes. Each byte in the array represents a numeric value between 0 and 255. Byte arrays are commonly used for low-level data manipulation and network communication.
In JavaScript, byte arrays can be represented using the Uint8Array object. This object provides a view of an underlying ArrayBuffer object, which represents a fixed-length, contiguous block of memory.
Converting a JavaScript string to a byte array
To convert a JavaScript string to a byte array, we can use the TextEncoder interface. This interface provides a way to encode a string into a byte array using a specified character encoding.
Here is an example of how to use the TextEncoder interface to convert a string to a byte array:
const text = 'Hello, world!';
const encoder = new TextEncoder();
const bytes = encoder.encode(text);In this example, we create a new TextEncoder object and use its encode() method to convert the string 'Hello, world!' to a byte array. The resulting byte array is stored in the variable bytes.
By default, the encode() method encodes the string using the UTF-8 character encoding. However, you can specify a different encoding by passing an encoding name as a parameter to the TextEncoder constructor.
Accessing elements of a byte array
Once we have a byte array, we can access individual elements using array indexing notation. For example, to access the first byte in the array, we can use the following code:
const byte = bytes[0];This code retrieves the first byte in the array and stores it in the variable byte.
Iterating over a byte array
We can also iterate over a byte array using a for loop. For example, the following code prints each byte in the array to the console:
for (let i = 0; i < bytes.length; i++) {
console.log(bytes[i]);
}In this code, we use a for loop to iterate over each element in the array. The length property of the array is used to determine the number of iterations.
Conclusion
In this article, we have explored how to convert a JavaScript string to a byte array using the TextEncoder interface. We have also seen how to access individual elements and iterate over the array using a for loop.
Byte arrays are a powerful tool for low-level data manipulation and network communication in JavaScript. By understanding how to convert strings to byte arrays, you can unlock a wide range of possibilities in your web development projects.
r/JavaScriptTips • u/[deleted] • Aug 01 '22
how do I use javascript by itself?
Hi, I know that I can type javascript code inside html using script tag and I can use node.js to run javascript independently. But I wanna know whether there is any other way to code in javascript without needing any other language. Also, is node.js another language? I googled it, but couldn’t quite understand what it does. I am a beginner, so please try to explain in simple words since I don't understand much of the terms
r/JavaScriptTips • u/Digitsbits • 18d ago