5 One-Liners to Mess Up Your Code Easily

5 One-Liners to Mess Up Your Code Easily

This trick could really lead to confusion. In JavaScript, you can also use the push function on Array.prototype. As the name suggests, this is a prototype or a template for arrays — and we can edit it.

Have you always wanted to play a trick on a fellow web developer? 

Or do you want to prove your useless knowledge? 

Here are some nasty one-liners to really turn a web project upside down.

Even if these are perhaps not tips for production-ready apps, you can learn something new about the web development world.

Messing up empty arrays

This trick could really lead to confusion. In JavaScript, you can also use the push function on Array.prototype. As the name suggests, this is a prototype or a template for arrays — and we can edit it.

But pushing on the prototype does not only bring predictable results — on the contrary. This is where it gets a bit strange and can cause a lot of confusion. Let’s look at an example.

Array.prototype.push("First")

let emtpyArray = []

So we pushed something on the prototype and then created an empty array. But because we added the element “first” directly to the template for all arrays, our empty array is not empty.

console.log(emptyArray) // []

console.log(emptyArray.length) // 0

So far, everything looks normal. But look at what is happening here:

console.log(emptyArray[0]) // "First"

Suddenly we found the element that we originally pushed on our prototype. Nevertheless, JavaScript will tell you that this array is empty and has a length of 0.

programming html web-development javascript css

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire CSS Developer

Want to develop a website or re-design using CSS Development? We build a website and we implemented CSS successfully if you are planning to **[Hire CSS Developer](https://hourlydeveloper.io/hire-dedicated-css-developer/ "Hire CSS Developer")**...

Web Animations with HTML, CSS, and JavaScript

Learn about some basic animations you can do with CSS, HTML and JavaScript and shows you how to add input animations to your site. Web animation is necessary for creating eye-catching websites that enable better conversions and attract users to click, view, and buy things on your website.

How to Create JavaScript carousel with HTML, CSS and JavaScript

Learn how to create JavaScript carousel with HTML, CSS and JavaScript. Learn how to create a JavaScript slider step by step. Now many people will just download a library to create a JavaScript carousel or JavaScript slider.

How to Create a Real-Time Clock for all Web Applications with HTML, CSS and JavaScript

In this tutorial, I will discuss creating a real-time clock for web applications. This is basically developed using HTML, CSS and JavaScript, Therefore, even though you’re a beginner for web development, this will not be hard for you to understand and add this clock for your web applications in future. Developing a real-time clock for all your web apps using JavaScript. How to Create A Real-Time Clock for Web Applications

Create a simple calculator using HTML, CSS, JavaScript

Let's create a cool calculator with HTML, CSS, JavaScript. This project is aimed to help beginners, who just started their javascript / frontend developer jo...