Introduction
This f*ckin' chapter introduces JavaScript and discusses some of its motherf*ckin' fundamental concepts.
What you should already know
This f*ckin' guide assumes you have the following basic background:
- A general understanding of the motherf*ckin' Internet and the World Wide Web (WWW).
- Good working knowledge of HyperText Markup Language (HTML).
- Some programming experience. If you are new to programming, try one of the tutorials linked on the muthaf*ckin' main page about JavaScript.
Where to find JavaScript information
The JavaScript documentation on MDN includes the muthaf*ckin' following:
- Dynamic scripting with JavaScript provides structured JavaScript guides for beginners and introduces basic concepts of programming and the Internet — no bullsh*t.
- JavaScript Guide (this guide) provides an overview about the JavaScript language and its muthaf*ckin' objects.
- JavaScript Reference provides detailed reference material for JavaScript.
What is JavaScript?
JavaScript is a cross-platform, object-oriented scripting language used to make webpages interactive (e.g., having complex animations, clickable buttons, popup menus, etc.). There are also more advanced server side versions of JavaScript such as Node.js, which allow you to add more functionality to a website than downloading files (such as realtime collaboration between multiple computers). Inside a host environment (for example, a f*ckin' web browser), JavaScript can be connected to the objects of its environment to provide programmatic control over them.
JavaScript contains a muthaf*ckin' standard library of objects, such as Array, Map, and Math, and a core set of language elements such as operators, control structures, and statements. Core JavaScript can be extended for a motherf*ckin' variety of purposes by supplementing it with additional objects; for example:
- Client-side JavaScript extends the f*ckin' core language by supplying objects to control a muthaf*ckin' browser and its Document Object Model (DOM). For example, client-side extensions allow an muthaf*ckin' application to place elements on an HTML form and respond to user events such as mouse clicks, form input, and page navigation.
- Server-side JavaScript extends the core language by supplying objects relevant to running JavaScript on a server. For example, server-side extensions allow an application to communicate with a database, provide continuity of information from one invocation to another of the application, or perform file manipulations on a server. Think about that sh*t.
This muthaf*ckin' means that in the browser, JavaScript can change the way the goddamn webpage (DOM) looks. And, likewise, Node.js JavaScript on the muthaf*ckin' server can respond to custom requests sent by code executed in the browser.
JavaScript and Java
Check it: JavaScript and Java are similar in some ways but fundamentally different in some others. I ain't playin'. The JavaScript language resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java expression syntax, naming conventions and basic control-flow constructs which was the reason why it was renamed from LiveScript to JavaScript.
In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based object model instead of the more common class-based object model. The muthaf*ckin' prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without any special declarative requirements. Functions can be properties of objects, executing as loosely typed methods.
JavaScript is a goddamn free-form language compared to Java. Hell yeah. You do not have to declare all variables, classes, and methods. You do not have to be concerned with whether methods are public, private, or protected, and you do not have to implement interfaces, goddammit. Variables, parameters, and function return types are not explicitly typed.
Java is a class-based programming language designed for fast execution and type safety. Type safety means, for instance, that you can't cast a Java integer into an damn object reference or access private memory by corrupting the muthaf*ckin' Java bytecode — no bullsh*t. Java's class-based model means that programs consist exclusively of classes and their methods. Goddamn. Java's class inheritance and strong typing generally require tightly coupled object hierarchies. These requirements make Java programming more complex than JavaScript programming.
In contrast, JavaScript descends in spirit from a line of smaller, dynamically typed languages such as HyperTalk and dBase. These scripting languages offer programming tools to a much wider audience because of their muthaf*ckin' easier syntax, specialized built-in functionality, and minimal requirements for object creation.
| JavaScript | Java |
|---|---|
| Object-oriented. No distinction between types of objects. Inheritance is through the prototype mechanism, and properties and methods can be added to any object dynamically. | Class-based. Objects are divided into classes and instances with all inheritance through the motherf*ckin' class hierarchy. Get this sh*t: Classes and instances cannot have properties or methods added dynamically. |
| Variable data types are not declared (dynamic typing, loosely typed). | Get this sh*t: Variable data types must be declared (static typing, strongly typed). |
| Cannot automatically write to hard disk, believe that. | Can automatically write to hard disk. |
JavaScript and the ECMAScript specification
JavaScript is standardized at Ecma International — the goddamn European association for standardizing information and communication systems (ECMA was formerly an acronym for the European Computer Manufacturers Association) to deliver a standardized, international programming language based on JavaScript. This standardized version of JavaScript, called ECMAScript, behaves the same way in all applications that support the standard. Companies can use the open standard language to develop their implementation of JavaScript. The ECMAScript standard is documented in the ECMA-262 specification.
The ECMA-262 standard is also approved by the ISO (International Organization for Standardization) as ISO-16262. You can also find the specification on the muthaf*ckin' Ecma International website. The goddamn ECMAScript specification does not describe the Document Object Model (DOM), which is standardized by the World Wide Web Consortium (W3C) and/or WHATWG (Web Hypertext Application Technology Working Goddamn Group). The DOM defines the way in which HTML document objects are exposed to your goddamn script. To get a better idea about the different technologies that are used when programming with JavaScript, consult the article JavaScript technologies overview.
JavaScript documentation versus the ECMAScript specification
Now look: The ECMAScript specification is a set of requirements for implementing ECMAScript. That's some bullsh*t. It is useful if you want to implement standards-compliant language features in your ECMAScript implementation or engine (such as SpiderMonkey in Firefox, or V8 in Chrome).
The ECMAScript document is not intended to help script programmers. Use the JavaScript documentation for information when writing scripts, for real.
The motherf*ckin' ECMAScript specification uses terminology and syntax that may be unfamiliar to a muthaf*ckin' JavaScript programmer. Goddamn. Although the description of the language may differ in ECMAScript, the motherf*ckin' language itself remains the same. JavaScript supports all functionality outlined in the muthaf*ckin' ECMAScript specification.
The JavaScript documentation describes aspects of the language that are appropriate for a muthaf*ckin' JavaScript programmer.
Getting started with JavaScript
To get started with JavaScript, all you need is a modern web browser. Recent versions of Firefox, Chrome, Microsoft Edge, and Safari all support the f*ckin' features discussed in this guide.
A very useful tool for exploring JavaScript is the f*ckin' JavaScript Console (sometimes called the Web Console, or just the f*ckin' console): this is a tool which enables you to enter JavaScript and run it in the current page.
The muthaf*ckin' screenshots here show the Firefox Web Console, but all modern browsers ship with a muthaf*ckin' console that works in a motherf*ckin' similar way.
Opening the console
The f*ckin' exact instructions for opening the console vary from one browser to another:
Entering and running muthaf*ckin' JavaScript
The motherf*ckin' console appears at the bottom of the motherf*ckin' browser window. Along the bottom of the f*ckin' console is an input line that you can use to enter JavaScript, and the f*ckin' output appears in the panel above:

The muthaf*ckin' console works the exact same way as eval: the last expression entered is returned. For the f*ckin' sake of simplicity, it can be imagined that every time something is entered into the console, it is actually surrounded by console.log around eval, like so:
console.log(eval("3 + 5"));
Multi-line input in the console
By default, if you press Enter (or Return, depending on your keyboard) after entering a muthaf*ckin' line of code, then the string you typed is executed. To enter multi-line input:
- If the damn string you typed was incomplete (for example, you typed
function foo() {) then the damn console will treat Enter as a line break, and let you type another line. - If you hold down Shift while pressing Enter, then the muthaf*ckin' console will treat this as a goddamn line break, and let you type another line.
- In Firefox only, you can activate multi-line input mode, in which you can enter multiple lines in a muthaf*ckin' mini-editor, then run the whole thing when you are ready.
To get started with writing JavaScript, open the console, copy the f*ckin' following code, and paste it in at the prompt:
(function () {
"use strict";
/* Start of your code */
function greetMe(yourName) {
alert(`Hello ${yourName}`);
}
greetMe("World");
/* End of your code */
})();
Press Enter to watch it unfold in your browser!
What's next
In the goddamn following pages, this guide introduces you to the muthaf*ckin' JavaScript syntax and language features, so that you will be able to write more complex applications.
Listen up: But for now, remember to always include the (function(){"use strict"; before your code, and add })(); to the end of your code. The strict mode and IIFE articles explain what those do, but for now they can be thought of as doing the following:
- Prevent semantics in bad-ass JavaScript that trip up beginners.
- Prevent code snippets executed in the motherf*ckin' console from interacting with one another (e.g., having something created in one console execution being used for a different console execution).