JavaScript Functions

Javascript: Object-oriented programing language that adds interactivity to websites.  Allows less server interaction as you can validate user input before sending it off to the server — this leads to lower server load & traffic.

Higher-order functions:  A function that takes other function(s) as arguments, or returns a function as its result.

Callback function:  A function that is passed into another function as an argument.  It’s being “called back” by the higher-order function.

Closure:  global variables can be made local or private using closures.  A closure gives you access to an outer function’s scope from an inner function.


JavaScript Functions

Exercism JS: Leap Year

Write a program that will take a year and report if it is a leap year.

The tricky thing here is that a leap year in the Gregorian calendar occurs:

  • Every year that is evenly divisible by 4
  • Except every year evenly divisible by 100
  • Unless the year is also evenly divisible by 400



Test cases.

Additional Solutions.

This problem was not challenging at all.  However, I did struggle with the JS fundamentals since I’m not at all familiar with JS yet.  This was good exposure on what to focus one:  module patterns and anonymous closures.

I found some resources here and here that may be helpful to read over.

Exercism JS: Leap Year