Question: I am using pure javascript (no jquery or any other framework) for animations.
Which one's more optimized? Creating classes for transition like:

CSS class:

```
    .all-div-has-this-class { transition: all 1s; }
    .class1 { left: 0; }
    .class2 { left: 30px; }

```

Javscript:

```
    testdiv.className += " class1";
    testdiv.className += " class2";

```

or just this in javascript => Initialize the `testdiv` position in the css then just do`testdiv.style.left = "30px";` in the js code?

By the way, these are all in setTimeout functions to set the properties according to timing. Also, it has to be only javascript without any jquery or any other framework specifically for animations.

Answer: 
Hoisting moves function declarations and variable declarations to the top, but doesn't move assignments.

Therefore, you first code becomes

```
var a;
function f() {
  console.log(a.v);
}
f();
a = {v: 10};

```

So when `f` is called, `a` is still `undefined`.

However, the second code becomes

```
var a, f;
a = {v: 10};
f = function() {
  console.log(a.v);
};
f();

```

So when `f` is called, `a` has been assigned.
It's due to the order. When you call the function in the first version, then the json isn't defined. So it tries to get property of undefined object. 

So it is necessary to call the function after declaring the object.