To Undefined or not to Undefined:

A brief history about JS

History

The early to mid-1990s was an important time for the internet. Key players like Netscape and Microsoft were in the midst of browser wars, with Netscape’s Navigator and Microsoft’s Internet Explorer going head to head.

vs

In May 1995, a Netscape programmer named Brendan Eich (Hired in February) developed a new scripting language (POC) in just 10 days. It was originally named Mocha, but quickly became known as LiveScript and, later, JavaScript.

We aimed to provide a “glue language” for the Web designers and part time programmers who were building Web content from components such as images, plugins, and Java applets. We saw Java as the “component language” used by higher-priced programmers, where the glue programmers—the Web page designers—would assemble components and automate their interactions using [a scripting language].

JavaScript vs Java

  • JavaScript and Java have almost nothing in common.
  • Many say it was a marketing tactic to divert some attention from Java, which was the most buzzed-about language at the time.
  • Java was too heavy and complicated to be run in the web.

 

For Non-Engineers

  • JavaScript didn’t exactly get off to the best start. It didn’t perform as well, and those developing in Java considered JavaScript more of a “UI glue” to be used mostly by designers and other non-engineers.
  • Programmers could react better to use events and compose interactive components.
  • At some point Javascript was the only language you could use to do logic in the Browser

 

AJAX Paper

  • In 2005 a paper released by Jesse James Garrett introduced Ajax, a revolutionary suite of technologies that included JavaScript. 
  • This paper is considered to be one of the founding backbones of the JavaScript community. At the time, JavaScript had many challenges, including its verbose nature when doing simple things and the incompatibility issues between browsers. The community responded with large and popular JavaScript frameworks and libraries, such as Dojo and Mootools and jQuery.

AJAX Web Model

Easy for Beginner Programmers!

What could go wrong?

Global Variables

  • Any assignation was considered a variable declaration that was at the same time a global variable.
  • Maybe you want to use a variable... but forgot to declare it, don't worry you can still use it!
foo = "bar"
myVariable = 1

if (true) {
  myVar = 2
}

console.log(myVar)

Semicolon Insertion

  • JavaScript will try to add semicolons to places where it thinks it makes sense to do so.
  • Semicolons are not required when writing JS, but the "compiler" will add them to run to code.
return 
{  status: true };


return; // undefined

return {
  status: true
}

Truthy & Falsy

 

 

Any value that's not on this "falsy" list is "truthy."

The specific list of falsy values in JavaScript is as follows

  • ​"" (empty string)
  • 0, -0, NaN (invalid number)
  • null, undefined
  • false

== OR ===

  • == checks for value equality
  • === checks for both value and type equality
  • == checks for value equality with coercion allowed
  • === checks for value equality without allowing coercion
var a = "42";
var b = 42;

a == b;			// true
a === b;		// false
var a = [1,2,3];
var b = [1,2,3];
var c = "1,2,3";

a == c;		// true
b == c;		// true
a == b;		// false

Null vs Undefined

  • Undefined is supposed to mean a variable has no value (or a property does not exist) because the programmer has not yet assigned it a value (or created the property).
  • Null is supposed to signal that a variable has no value because the programmer purposefully cleared the value and set it to null.

So you should only ever set variables to null. Never to undefined.

...UNLESS you are working with existing code or a specific api or library explicitly checking for undefined, then of course to force the behavior you want you’d have to make an exception.

Timeline

Useful Links

  • https://www.springboard.com/blog/data-science/history-of-javascript/
  • https://thenewstack.io/brendan-eich-on-creating-javascript-in-10-days-and-what-hed-do-differently-today/
  • https://www.youtube.com/watch?v=GxouWy-ZE80&ab_channel=TechTalk
  • https://www.youtube.com/watch?v=JxAXlJEmNMg&t=1s&ab_channel=YUILibrary

Thanks!

To undefined or not to undefined

By Cesar Guerrero Rincon

To undefined or not to undefined

  • 112