brianleroux / wtfjs Goto Github PK
View Code? Open in Web Editor NEWwtfjs.com!
Home Page: http://wtfjs.com
License: Do What The F*ck You Want To Public License
wtfjs.com!
Home Page: http://wtfjs.com
License: Do What The F*ck You Want To Public License
I think this is just WTF.
[jann@Jann-PC dnode-protocol master]$ node
> var regexp = /\+((?:\+)?[\w\-]+)*(?:\.v\d+\.\d+\.\d+)?(?:\.js)$/g;
> function f(){console.log(regexp.exec('/socket.io+websocket.v0.8.10.js') != null);}
> setInterval(f, 100)
{ ontimeout: [Function] }
> true
false
true
false
true
false
true
false
http://wtfjs.com/2013/08/07/Math.max()-behaviour
isn't schareable on twitter. 😭
Made by hand, rather than using wtfjs, but I'm sure it's easy to redo:
function lucas(n) { for(_=++[+[]][+[]],__=++[_][+[]]<<++[_][+[]]<<++[_][+[]]<<_;__>+[];_=++[+[]][+[]]+(++[+[]][+[]]/_),__--);for(__=_;-++[+[]][+[]]+--n;_*=__);return(++[+[]][+[]]/++[++[+[]][+[]]][+[]]+_)|+[]; }
Computes the golden ratio φ by evaluating the continued fraction for the golden ratio over 64 iterations, then computes the Lucas number lucas(n) directly as round(φ^(n-1)).
(more detailed composition explained over at https://pomax.github.io/#gh-weblog-1418775170598)
This page is in the index, but actually attempting to open it leads to a 400 error. Is it related to the parsing of the URL seeing "[]" as a trouble input and bailing out due to what it considered a security issue?
EDIT: The link on this issue is mangled and the right brackets are percent-encoded which leads to a 404 not found error. Perhaps move the page?
In post "false isnt false":
true == 'true' // true
but my FF and Chrome say "false". Is it true: see http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3
https://wtfjs.com/wtfs/2013-03-06-false-isnt-false
It seems like this has since been changed, or it was not accurate.
It also contradicts this one.
https://wtfjs.com/wtfs/2013-04-18-true-story-bro
If it helps I can create a PR to remove it/ Update it to say it no longer applies.
yes.
I'm surprised no one uncovered that here:
new Date(10) == new Date(10) // false
new Date(10) < new Date(11) // true
new Date(11) > new Date(12) // false
new Date(11) > new Date(10) // true
Two object instances are always unequal. But they decided to overload operator <
and >
for Date
and not ==
. This renders the whole thing useless.
Is it just me or is 2018-19-01-weird-number-addition.md missing from the overview?
It is important to note that in this one https://wtfjs.com/wtfs/2010-02-12-maths-fun even the case where:
0.1 + 02 === 0.3 // false
is the same for Python:
0.1 + 0.2 == 0.3 // False
So this is not a quirk of just JS but it also stems to other languages like Python and it is not a problem of the language but more so an issue that stems from the way that computers store numbers (binary). I believe that this example should be removed because it is not specific to JS.
var a = [1,2,3];
Array.prototype.isPrototypeOf(a); // true
var b = 123;
Number.prototype.isPrototypeOf(b); // false
var c = new Number(123);
Number.prototype.isPrototypeOf(b); // true
typeof b; //number
typeof c; //object
b == c; //true
b === c; //false
c += 1; //124
typeof c; //number
typeof null; //object
This page contains the following errors:
error on line 19 at column 14: Opening and ending tag mismatch: code line 0 and p
Below is a rendering of the page up to the first error.
var x = 12;
var y = 12;
x === y // true
var x = new Number(12);
var y = new Number(12);
x === y // false
x == y // false
var x = y = new Number(12);
x === y // true
While it might be useful to set two variables as references to the same Number
instance object, the object instance does not have any method available to mutate it's internal primitive value, so this feature ended up only useful in confusing people.
Probably something inherited from Java?
Not empty array don't contains it element:
var a = [,]; alert(a.indexOf(a[0]));
alert
will return -1
. The main point in this example is difference between uninitialized
and undefined
values.
The problem is in this:
a.length
is 1
. So array has some elements. But a[0]
is undefined
and a.indexOf(undefined)
will return -1
.
Undefined
is the javascript primitive
type. Uninitialized
means the value that don't have any javascript type.
P.S. I'm trying to find why a[0]
return undefined now for complete explanation.
need a better solution
JSON.stringify(Infinity) === "null" // Of course, I know that the space is non-finite and mostly empty but I just want the string
Hi again, I'm sorry but there are 3 typos in my last post "hexadecimal weirdness"
Can you put
"In JS you can represent numbers in hexadecimal, right?"
instead of
"In JS you an represent numbers in haxadecimal, right?"
and
alert(hex.toString(16)); // 0xFF5500
instead of
alert(hex.toString(16); // 0xFF5500
Thanks!
n = 0; while (Math.pow(2, n) < Math.pow(2, n) + 1) { n++; }
The last WTF:
",,," == Array((null,'cool',false,NaN,4)); // true
can be explained in the following way:
null, 'cool', false, NaN, 4 => 'cool', false, NaN, 4 => false, NaN, 4 => NaN, 4 => 4
",,," == new Array(4); // true
So really, it's just some magic behind the comma operator.
Never mind sorry
Great to see the site back up again—I'd like to report a few issues I've noticed while browsing the site.
The first entry on https://wtfjs.com/, "2016 03 19 wierd instanceof", leads to a page that just says "wtf! not found"
You're not setting the charset to UTF-8. E.g. https://wtfjs.com/wtfs/2014-02-20-math-pow shows "— @123jimin" instead of "— @123jimin" in my browser
https://wtfjs.com/wtfs/2013-12-15-charAt-is-not-the-same-as-[] is just an empty page
https://wtfjs.com/wtfs/2010-04-31-isNaN links to https://wtfjs.com/2010/02/12/null-is-not-an-object which just shows {"message":"Missing Authentication Token"}
The link should be https://wtfjs.com/wtfs/2010-02-12-null-is-not-an-object
https://wtfjs.com/wtfs/2015-04-23-screwy-negative-array-index is missing newlines
Lots of pull requests which hasn't been merged and the website hasn't been updated since 2016
eh
/
currently redirects to /wtfs
. That's not the current behavior/wtfs
works but /wtfs
doesn't. That's not the current behaviorshared/
logic be preserved?Hi guys,
looks like the website is down?
The last time I tried it just showed "nginx correctly installed"?
It might be a good idea to set it up on github.io?
if (-1 && -100 && 100) console.log('wtf?')
[code=es:0]
"use strict";
var foo, bar, baz;
foo = function(bar){
if(bar === 0){
return(1);
}else if(bar < 0){
return(-1);
}else{
return(bar * arguments.callee(bar - 1));
}
}
foo(5);
[/code]
Does not work in strict mode, throws a type error.
Can someone tell me?
"Why am I a " + typeof + ""; // "Why am I a number"
Because in this context the (second) +
character isn't an addition operator but a unary + operator.
It is used to cast values to a number. In this case the empty string is casted to the number 0
, of which the type is (obviously) "number"
.
Remember about +new Date()
? This +""
is just like that.
So wrapped in logical groups:
"Why am I a " + ( typeof ( +"" ) ); // "Why am I a number"
You better fix your RSS feed, cause it's totally broken...
regards
http://wtfjs.com/2013/01/28/array-comparison
'Did you know that JavaScript can compare arrays using lexicographical ordering?'
With >, >=, <, <=, they're both converted to strings, and JavaScript will compare each character code in order. Note also,
[10, 2, 3] > [2, 2, 3] // false
Hello everybody,
This repository seems to be inactive for a quite long time. It has 13 open issues and 35 Pull Requests. That's why I create a new github organization to fork and maintain this repository.
Here is it: https://github.com/wthjs/wtfjs
If you want to maintain this repository, please let know by leaving comment on this issue.
Thanks.
The section "false isnt false" claims that:
true == 'true' // true
false == 'false'; // false
But in fact the first line also resolves to false
. Please correct it!
You may prefer to write that section like this:
false == '0'; // true
false == 'false'; // false
Again some misunderstanding
There is a small difference between
/[/ + "javascript"[0] + '///'
and
/[/ + "javascript"[0] + '///'
On at least some Markdown processors, the line containing "```" can contain the language, such as:
``` javascript
function code() {yield 5; return null;}
```
Could display as
function code() {yield 5; return null;}
This means that one potential solution to fixing the syntax highlighting is to simply add the "javascript" language specification on the initial "```" line. Please check whether it actually works for your posts already, or if some additional plugin to support the Javascript language is needed.
EDIT: This page already has that fix. You should try to install a syntax highlighting plugin to your Markdown install and check on this page, before making this change. Perhaps highlight.js?
EDIT 2: See this page for how to enable syntax highlighting with Marked.JS.
What is described in the 2014-01-29-regular-expression-and-slash post is expected Regex behavior, not a JS WTF.
Since readdir doesn't guarantee the order of returned filenames there are two missing calls to sort() in the code of post.js.
--- a/node-code-blog/post.js +++ b/node-code-blog/post.js @@ -25,3 +25,3 @@ Post.paginate = function(page) { fs.readdir(postsPath, function(err, files){ - var posts = Post.all(files).reverse() + var posts = Post.all(files.sort().reverse()) , count = 5 @@ -52,3 +52,3 @@ Post.rss = function(title, desc, domain) { s += 'http://' + domain + '/'; - var posts = Post.all(fs.readdirSync(postsPath).reverse()); + var posts = Post.all(fs.readdirSync(postsPath).sort().reverse()); for (var i = 0; i < 5; i++) {
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.