Hello, my name is: Amy

Batch of Coding questions

What is the value of foo?

var foo = 10 + '20';

// --> '1020'

Adding a number and string together first converts number to string.


What is the return value?

console.log("i'm a lasagna hog".split("").reverse().join(""));

// --> goh angasal a m'i

What is the value of window.foo?

( window.foo || ( window.foo = "bar" ) );

// --> 'bar' (assuming that window doesn't actually have a 'foo' property assigned)

What is the outcome of the two alerts below?

var foo = "Hello";
(function() {
  var bar = " World";
  alert(foo + bar);
})();
alert(foo + bar);

// --> alert ( Hello World )
// --> alert ( Helloundefined ) // <-- actually doesn't execute bc bar is not defined

(Scoping!)


What does the following code print?

console.log('one');
setTimeout(function() {
  console.log('two');
}, 0);
console.log('three');
// --> one
// --> three
// --> two

Even though the timeout is for '0', that function is still placed in the event queue which means it is processed after console.log('three')

Comments