The Drupal alternate better method to add jQuery

We usually add

$(document).ready(function () {
  // Do some fancy stuff.
});

However in drupal 8 we have better method.