Linked Questions
36 questions linked to/from What is the "double tilde" (~~) operator in JavaScript?
254
votes
13
answers
35k
views
What does ~~ ("double tilde") do in Javascript?
I was checking out an online game physics library today and came across the ~~ operator. I know a single ~ is a bitwise NOT, would that make ~~ a NOT of a NOT, which would give back the same value, ...
17
votes
4
answers
7k
views
~~ vs parseInt? [duplicate]
Possible Duplicate:
What is the “double tilde” (~~) operator in JavaScript?
The D3 tutorial gives a function that produces a random sequence:
var t = 1297110663, // start time (...
21
votes
1
answer
28k
views
Whats does ~~ mean in javascript? [duplicate]
I've been reading through some code and noticed a function:
randint: function(n) {
return ~~(Math.random() * n)
}
I know ~ means "not" but how does ~~ change this return statement?
12
votes
3
answers
3k
views
What does ~~ do in JavaScript/node.js? [duplicate]
Possible Duplicate:
What is the “double tilde” (~~) operator in JavaScript?
I found this snip of code in a node.js library's source. What effect does ~~ have on the input variable?
...
0
votes
4
answers
89
views
Why it is leaving the decimals [duplicate]
Possible Duplicate:
What is the “double tilde” (~~) operator in JavaScript?
My Code:
<SCRIPT type="text/javascript">
var num = 2.52;
alert(~~num);
</SCRIPT>
It is giving the result ...
0
votes
0
answers
96
views
Need help understanding how this JS code is generating UUID [duplicate]
I got this piece of code for generating UUID in case the browser doesn't support crypto.randomUUID.
I need help understanding how this works. A step by step process would be much appreciated. Would ...
2
votes
0
answers
73
views
What exactly does the Javascript ~~ operator do? [duplicate]
Possible Duplicate:
What is the “double tilde” (~~) operator in JavaScript?
I was wondering for a time now what exactly the ~~ operator does in javascript.
It seems it does essentially the same as ...
0
votes
0
answers
25
views
Meaning of some operators in javascript [duplicate]
What means the following piece of code in javascript:
var lO1 = ~~$('html').css('padding-left').replace('px', '');
2613
votes
34
answers
2.7m
views
Generate random number between two numbers in JavaScript
Is there a way to generate a random number in a specified range with JavaScript ?
For example: a specified range from 1 to 6 were the random number could be either 1, 2, 3, 4, 5, or 6.
313
votes
27
answers
410k
views
Random alpha-numeric string in JavaScript?
What's the shortest way (within reason) to generate a random alpha-numeric (uppercase, lowercase, and numbers) string in JavaScript to use as a probably-unique identifier?
58
votes
9
answers
110k
views
How to perform a bitwise operation on floating point numbers
I tried this:
float a = 1.4123;
a = a & (1 << 3);
I get a compiler error saying that the operand of & cannot be of type float.
When I do:
float a = 1.4123;
a = (int)a & (1 <<...
54
votes
4
answers
16k
views
What does the operator |= do in JavaScript?
I found the following code in a JS project:
var a = new Array();
a[0] = 0;
for (var b = 0; b < 10; b++) {
a[0] |= b;
}
What does the |= do in the body of the for loop?
The code example is ...
24
votes
7
answers
48k
views
Fastest way to cast a float to an int in javascript?
Let's say I have x = 12.345. In javascript, what function floatToInt(x) has the fastest running time such that floatToInt(12.345) returns 12?
25
votes
3
answers
33k
views
Javascript performance: reduce() vs for-loop
I was attempting this Codewars challenge and the problem involves finding the divisors of a number and then calculating the sum of these divisors squared. I found two approaches to this problem.
The ...
11
votes
7
answers
20k
views
Check for NaN, null and >=0 in one condition
I have a var a;
Its value can be NaN, null and any +ve/-ve number including 0.
I require a condition which filters out all the values of a such that only >=0 values yield a true in if condition.
...