How to use arrow function notation

Can some one help me convert the following code into arrow notation. Also where can I find resources regarding arrow notation.

var p;

function side(a, c) {
    "use strict";

    function mul(y) {
        return y * y;
    p = mul(a) + mul(c);
    return p;
console.log(side(2, 3));

Personally, I would write it like this:

var p;

const mul = (y) => ( y*y );
const side = (a, c) => ( mul(a) + mul(c) );
console.log(side(2, 3));

In terms of resources, freeCodeCamp has a few lessons, and W3SCHOOLS

Yah I did the same. But I want to nest the mul function inside side function. Is that possible in arrow notation?


you can write your function like this:

const side = (a, c) => {
    const mul = y => (y * y);
    return (mul(a) + mul(c));

console.log(side(2, 3)) // 13

I think that actually you don’t need the variable p.

1 Like