Skip to content

andrew-k9/javascript_odities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Obfuscated Javascript

This is a project that demonstrates the weird type-casting that Javascript can do! based off of this github

Background

Since Javascript automatically casts types to other types in operations, you can get a lot of weird results like

  9 + "1"; // => "91"
  9 - "1";  // => 8
  [] + []; // => ""

How it works

Using javascripts casting logic, you can start to manipulate the empty array to basically whatever!

  []; // can be 0, "", true
  ![]; // => `false` since `[]` is truthy
  !![]; // => `true`
  +[]; // => `0` since + can be a unary operator that casts its operand to a number
  +!+[]; // => `1` since `!0` is `true` and `true` casts to 1

Once we have those building blocks, we can start to get letters from casting these primitive types. Lets walk through a simple example with getting the letter t. Each line below returns t:

  "true"[0];
  (true+"")[0];
  (!![]+"")[0];
  (!![]+[]+[])[0];
  (!![]+[]+[])[+[]];

So, for free, you can get the letters from true, false, NaN, undefined, etc.

How to run

In this directory, put

  const { parser } = require('./lib/obfuscate.js');

at the top of your file. Then call it using a string formatted like so '"whatever to change"'

  const hello_world = parser('"hello world"');

About

Based off of an esoteric js style

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published