(click anywhere to close)

[JavaScript] Keywords & Arrow Functions

category: Website | course: Advanced Javascript | difficulty:
1. Keywords
2. Arrow Functions

The basic course already talked about nearly every keyword there is, but there are still four of them left. I also want to introduce a nifty little feature that actually has to do with typing as little keywords as possible.


The debugger keyword stops the execution of JavaScript – so no code beyond that point will run – and opens the browser’s debugger (if available).

console.log("Executed A");
console.log("Executed B"); //Won't run.

The typeof keyword is used to find the type of a certain value.

console.log(typeof "Juan"); //Prints string (types are lowercase, and without quotes)

The super keyword is used to call functions on an object’s parent. It is typically used with classes to call the parent constructor, or a specific method.

super(arguments); //Calls the parent constructor

The delete keyword deletes an object’s property, an entire object, or an element from an array.

var obj = {a:0, b:1, c:2};
delete obj.a;
console.log(obj.a); //Prints undefined

It can’t delete values from a variable declared with var, or pre-defined properties such as Math.PI

Arrow Functions

Very often, you write functions that you simply want to return a certain value, given a few parameters. You could do this with the regular function syntax, but writing that function keyword over and over can become a bit of a bore, and that’s why a shorter expression has been invented: the arrow function.

The syntax is

(param1, … paramn) => { returnStatements }

If you have only a single parameter, you can ditch the parentheses. If you have no parameters, you can just leave that space empty. Likewise, if you have only a single statement, you don’t have to use the braces.

//These are all the same
var x = (a) => { 5*a };
var x = a => {5*a};
var x = a => 5*a;

console.log(x(15)); //Prints 5*15 = 75

If you want the arrow function to return an object, you have a problem, because objects are also created using braces. To solve this, parenthesize the statement(s).

var x = (a,b,c) => ({ firstProp:a, secondProp:b, thirdProp:c });
Do you like my tutorials?
To keep this site running, donate some motivational food!
Chocolate Milk