Email Subscription Form

Saturday, March 21, 2020

Adventures in Node: Arrow Functions

This year I've been feeling an urge to really learn a programming language.  There are lots of languages I know well enough to write automation code in- C#, Java, Javascript, and so on- but I decided I wanted to really dive into one language and learn to really understand it.

I decided to go deep with Node.js.  Node is essentially Javascript with a server-side runtime environment.  It's possible to write complete applications in Node, because you can code both the front-end and the back-end of the application.  And I was fortunate enough to find this awesome course by Andrew Mead.  Andrew does a great job of making complicated concepts really simple, so as I am taking the course, I'm finding that things that used to confuse me about Node finally make sense!  And because I like sharing things I've learned, I'll be periodically sharing my new-found understanding in my blog posts.


I'll start with arrow functions.  Arrow functions have been around for a few years now, but I've always been confused by them, because they weren't around when I was first learning to write code.  You may have seen these functions, which use the symbol =>.  They seem so mysterious, but they are actually quite simple!  Arrow functions are simply a way to notate a function to save space and make code easier to read.  I'll walk you through an example.  We'll start with a simple traditional function:

const double = function(x) {
     return x + x
}

double is the name of the function.  When x is passed into the function, x + x is returned.  So if I called the double function with the number 3, I'd get 6 in response.

Now we're going to replace the function with an arrow:

const double = (x) =>  {
    return x + x
}

Note that the arrow comes after the (x), rather than before.  Even though the order is different, function(x) and (x) => mean the same thing.

Now we're going to replace the body of the function { return x + x } with something simpler:

const double = (x) => x + x

When arrow functions are used, it's assumed that what comes after the arrow is what will be returned.  So in this case, x + x means the same thing as { return x + x }.  This is only used if the body of the response is relatively simple.

See?  It's simple!  You can try running these three functions for yourself if you have node installed.  Simply create an app.js file with the first version of the function, and add a logging command:

console.log(double(3))

Run the file with node app.js, and the number 6 will be returned in the console.

Then replace version 1 of the function with version 2, run the file, and you should get a 6 again.  Finally, replace version 2 with version 3, and run the file; you should get a 6 once again.

It's even possible to nest arrow functions!  Here's an example:

const doublePlusTen = (x) => {
    const double = (x) => x + x
    return double(x) + 10
}

The const double = (x) => x + x is our original function.  It's nested inside a doublePlusTen function.  The doublePlusTen is using curly braces and a return command, because there's more than one line inside the function (including the double function).  If we were going to translate this nested function into plain English, it would look something like this:

"We have a function called doublePlusTen.  When we pass a number into that function, first we pass it into a nested function called double, which takes the number and doubles it.  Then we take the result of that function, add 10 to it, and return that number."  

You can try out this function by calling it with console.log(doublePlusTen(3)), and you should get 16 as the response.

Hopefully this information will help you understand what an arrow function is doing the next time you encounter it in code.  You may want to start including arrow functions in your own automation code as well.  Stay tuned in the coming weeks for more Adventures in Node posts!

11 comments:

  1. http://chennaitraining.in/dotnet-training-in-chennai/
    http://chennaitraining.in/etl-testing-training-in-chennai/
    http://chennaitraining.in/salesforce-admin-training-in-chennai/
    http://chennaitraining.in/salesforce-developer-training-in-chennai/
    http://chennaitraining.in/sap-hana-training-in-chennai/
    http://chennaitraining.in/sap-mm-training-in-chennai/
    http://chennaitraining.in/sap-sd-training-in-chennai/

    ReplyDelete
    Replies





    1. Hello World
      I’m hacker and Services provider
      interested in any thing i do fair deals.
      I will show you each and everything to start business
      also teaching Hacking / spamming short courses
      I have all tools that you need to spam

      .. Western Union transfer
      .. Credit cards
      .. Money adders
      .. Bill paying
      .. College fee
      .. Fake documents
      .. Grade change

      Contact:

      omoskovitz@gmail.com


      Delete
  2. Hey Guys !

    USA Fresh & Verified SSN Leads with DL Number AVAILABLE with 99.9% connectivity
    All Leads have genuine & valid information

    **HEADERS IN LEADS**
    First Name | Last Name | SSN | Dob | DL Number | Address | City | State | Zip | Phone Number | Account Number | Bank Name | Employee Details | IP Address

    *Price for SSN lead $2
    *You can ask for sample before any deal
    *If anyone buy in bulk, we can negotiate
    *Sampling is just for serious buyers

    ==>ACTIVE, FRESH CC & CVV FULLZ AVAILABLE<==
    ->$5 PER EACH

    ->Hope for the long term deal
    ->Interested buyers will be welcome

    **Contact 24/7**
    Whatsapp > +923172721122
    Email > leads.sellers1212@gmail.com
    Telegram > @leadsupplier
    ICQ > 752822040

    ReplyDelete
  3. Hello all
    am looking few years that some guys comes into the market
    they called themselves hacker, carder or spammer they rip the
    peoples with different ways and it’s a badly impact to real hacker
    now situation is that peoples doesn’t believe that real hackers and carder scammer exists.
    Anyone want to make deal with me any type am available but first
    I‘ll show the proof that am real then make a deal like

    Available Services

    ..Wire Bank Transfer all over the world

    ..Western Union Transfer all over the world

    ..Credit Cards (USA, UK, AUS, CAN, NZ)

    ..School Grade upgrade / remove Records

    ..Spamming Tool

    ..keyloggers / rats

    ..Social Media recovery

    .. Teaching Hacking / spamming / carding (1/2 hours course)

    discount for re-seller

    Contact: 24/7

    fixitrogers@gmail.com

    ReplyDelete
  4. Selling USA FRESH SSN Leads/Fullz, along with Driving License/ID Number with good connectivity.

    **PRICE FOR ONE LEAD/FULLZ 2$**

    All SSN's are Tested & Verified. Fresh spammed data.

    **DETAILS IN LEADS/FULLZ**

    ->FULL NAME
    ->SSN
    ->DATE OF BIRTH
    ->DRIVING LICENSE NUMBER
    ->ADDRESS WITH ZIP
    ->PHONE NUMBER, EMAIL
    ->EMPLOYEE DETAILS

    ->Bulk order negotiable
    ->Minimum buy 25 to 30 leads/fullz
    ->Hope for the long term business
    ->You can asked for specific states too

    **Contact 24/7**

    Whatsapp > +923172721122

    Email > leads.sellers1212@gmail.com

    Telegram > @leadsupplier

    ICQ > 752822040

    ReplyDelete
  5. Hi Guy's

    Fresh & valid spammed USA SSN+Dob Leads with DL available in bulk.

    >>1$ each SSN+DOB
    >>2$ each with SSN+DOB+DL
    >>5$ each for premium (also included relative info)

    Prices are negotiable in bulk order
    Serious buyer contact me no time wasters please
    Bulk order will be preferable

    CONTACT
    Telegram > @leadsupplier
    ICQ > 752822040
    Email > leads.sellers1212@gmail.com

    OTHER STUFF YOU CAN GET

    SSN+DOB Fullz
    CC's with CVV's (vbv & non-vbv)
    USA Photo ID'S (Front & back)

    All type of tutorials available
    (Carding, spamming, hacking, scam page, Cash outs, dumps cash outs)

    SMTP Linux Root
    DUMPS with pins track 1 and 2
    Socks, rdp's, vpn's
    Server I.P's
    HQ Emails with passwords

    Looking for long term business
    For trust full vendor, feel free to contact

    CONTACT
    Telegram > @leadsupplier
    ICQ > 752822040
    Email > leads.sellers1212@gmail.com

    ReplyDelete
  6. Excellent and professional investigative services. I hired Mr White for a very private and difficult matter of hacking my wife's phone and he far exceeded my expectations. He helped me get some info such as whatsApp, facebook, text messages, call logs and even phone conversations that I needed for proof of her secretive affair. The first time we spoke, we had a very long phone consultation in which he gave me all my options that he could think of to resolve my case, and he even recommended I try other options before hiring him, which shows that he is honest. I decided to hire him and I am glad I did. He is a fantastic investigator and a hacker; to all loyal partners out there if you have a dishonest partner don't hesitate to send him a mail Contact: Whitehatstech@gmail.com

    ReplyDelete
  7. vI just have to introduce this hacker that I have been working with him on getting my credit score been boosted across the Equifax, TransUnion and Experian report. He made a lot of good changes on my credit report by erasing all the past eviction, bad collections and DUI off my credit report history and also increased my FICO score above 876 across my three credit bureaus report you can contatc him for all kind of hacks . Email him here via Email him here via hackintechnology@gmail.com or whatsapp Number: +1 410 635 0697.

    ReplyDelete
  8. I have read this article. This article is about programming languages. Thanks for sharing valuable information with your readers. Keep posting more article with us. Now it's time to avail https://beelinebuild.com/ for more information.

    ReplyDelete
  9. I can’t stop thanking this guys for helping me recover back my money, My name is Tom Rani a young single mother. A few months back I was duped by a trading platform with the promise of making daily profits of 18%, which caught my attention to invest, i ended up losing over 8.7BTC to the trading platform. In process of recovering it back, I kept meeting fake recovery expert, I was scammed multiple times, last year was indeed a terrible year for me, since then I have trouble taking care of myself as well as feeding my two 2years old kid nor was i able to pay off my bills. until I confide in a close friend of mine since things are becoming so difficult for me, she then introduced me to crypto recovery group of hacker that uses Rootkits Spammers, top-notch software, he's known as Jamesmckaywizard, I reached out to him with the last hope I had left, their service is a little bit high but I was able to make a part payment with the help of my friend, their services is so smooth quick and super fast with good results, I was very happy as they successfully recovered back more than what i lost to those heartless scammers. It was indeed worth it, it was truly amazing. As I strongly advise anyone experiencing similar or who has fallen a victim to any scammer or anyone who has invested in a fake platform like me, this guys are good with Recoveries and hacking of any range, do reach out to them if you're experiencing any of these to get back your had earned money, Contact them @: WHAT'S APP: +91 98632 93475 OR EMAIL: jamesmckaywizard@gmail.com ...........Try them and thank me later. I can’t stop thanking this guys for helping me recover back my money,

    ReplyDelete
  10. Crypto Currency’s has been the general direction of the economic development which individuals like to save up with instead of banks. I lost my bitcoin to fake blockchain impostors on Facebook when they contacted me as blockchain official support and I fell for their mischievous act. Whatever information I gave them, made them gain access into my blockchain wallet and made away with my $155,000. I lost it and almost in a comma because this were all my savings waiting for bitcoin rate to improve. I wrote directly to the specialist whom I was referred to by my sister-in-law ( softwarespecialist@usa.com) explaining my loss. He helped me recover my crypto in just after 3 days and he as well helped me launch the recovery program all thanks to his expertise. I believe that someone out there will need his great services that is why I am referring him to someone. Reach out to the recovery specialist to recover you lost funds from any form of online.

    ReplyDelete

New Blog Location!

I've moved!  I've really enjoyed using Blogger for my blog, but it didn't integrate with my website in the way I wanted.  So I...