F
F
fuckman2016-02-27 23:47:54
JavaScript
fuckman, 2016-02-27 23:47:54

Why in some js guides do the authors deliberately not put a semicolon?

In some guides, the authors do not put a semicolon at the end of the instructions. Why do they do it? Is this a feature of Babel?

// Send a request to the login URL and save the returned JWT
  login(context, creds, redirect) {
    context.$http.post(LOGIN_URL, creds, (data) => {
      localStorage.setItem('id_token', data.id_token)

      this.user.authenticated = true

      // Redirect to a specified route
      if(redirect) {
        router.go(redirect)        
      }

    }).error((err) => {
      context.error = err
    })
  },

Taken from here: vuex-basics-tutorial , Build an App with Vue.js

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Aves, 2016-02-28
@fuckman

Most likely a new fashion trend - https://github.com/feross/standard

A
Anton Natarov, 2016-02-28
@HanDroid

Possibly demonstrate the advantage of language. Because at the compilation stage, he himself substitutes a semicolon where necessary. Although I myself don’t understand why they still don’t write in strict mode) As they say, it’s better to be safe than sorry.

V
Vitaliy Vinnichenko, 2016-02-28
@HollaOut

Syntactically, this is correct, but at some points the code will not work.
For example:

alert( "Error" )
[1, 2].forEach(alert)

Therefore, it is advisable to use semicolons to avoid such cases.
In details

V
Vlad Timofeev, 2016-02-28
@PyTiMa

Are Semicolons Necessary in JavaScript?
And yes, for sure Aves is right.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question