---
title: "Ninja Object Properties in Scripting Languages"
description: "10 hours ago, came across atrick-wied’s ninja object properties in JavaScript, that speaks of code as below. var x = {}."
url: "https://h3manth.com/scribe/ninja-object-properties-scripting-languages/"
canonical_url: "https://h3manth.com/scribe/ninja-object-properties-scripting-languages/"
markdown_url: "https://h3manth.com/scribe/blog/ninja-object-properties-scripting-languages.md"
publishDate: "2012-06-06T00:00:00.000Z"
author: "Hemanth HM"
category: "python"
tags: ["ruby","python","javascript"]
word_count: 163
reading_time_minutes: 1
x_markdown_tokens: 342
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Ninja Object Properties in Scripting Languages

> 10 hours ago, came across atrick-wied’s ninja object properties in JavaScript, that speaks of code as below. var x = {}.

10 hours ago, came across atrick-wied's ninja object properties in JavaScript, that speaks of code as below.

var x = {}; x[""] = 1; x[" "] = 2; x[" "] = 3;

console.log(x)

x= {}

x[String.fromCharCode(1)] = 1; x[String.fromCharCode(2)] = 2; x[String.fromCharCode(3)] = 3; x[String.fromCharCode(4)] = 4;

console.log(x);

This is not very obfuscated JS-code, but indeed fun to see spaces as object properties and space as **✐**

**On the same lines out of interest tried exploring the same property in other languages**

**Python:**

> > > class A(object): pass... a = A() setattr(a,' ',1) setattr(a,' ',2) setattr(a,'',3) getattr(a,'') 3 

**Ruby:**

irb(main):001:0> a={} => {} irb(main):002:0> a[' ']=1 => 1i rb(main):003:0> a[' ']=2   
=> 2 irb(main):004:0> a[' '] => 1 irb(main):005:0> a[' ']   
=> 2 

**Perl:**

$x={}; $x->{' '} = 1; say $x->{' '}; $x->{' '} = 2; say $x->{' '}; $x->{' '} = 3; say $x->{' '}; 

**So it appears most of the major scripting languages have the ninja object property in them!**
