Adventures in Web Development.

What I Learned From AppendTo JavaScript 101

I started learning JavaScript at appendTo developer learning center and found out things
about JavaScript that I didn’t know before. Here are some of those:

Automatic type coercion – concatenating a string and a number doesn’t result in an error, the type of the other variable
is converted to the type of the other. Here’s an example:

12

console.log(25+"yoyos");//output: "25yoyos"

If for example the result of an operator is not a number then we get NaN.

1

"hello"-"world";//output: NaN

There’s only one number data type in JavaScript which means that 52 and 52.0 are the same.

JavaScript is loosely typed which means that a variable can represent any data type at a given time. Here’s an example:

123

varx=2;//numberx=true;//booleanx="Im a string";//string

In the example above we changed the type of the variable x from number, to boolean and finally to a string. This is perfectly fine in
JavaScript unlike in other languages where you have to explicitly specify the type and you will have to stick with that while the program executes.

There are 7 falsy values:

1234567

0-0nullundefinedfalseNaN""

Force conversion from a specific type to boolean. This will most likely be used in determinining whether a variable contains a truthy or falsy value.

12

!!5;//output: true;!!undefined;//output: false;

typeof operator allows you to determine the type currently represented by a variable. Here’s an example:

123456

typeof"Im a string";//output: "string" typeof2;//output: "number"typeof2.2//output: "number" - like I said earlier there's only one number type in JavaScripttypeofnull//output: "object" - yes JavaScript is pretty nasty sometimestypeofNaN//output: "number" - Not a Number has a type of Number, pretty cooltypeofundefined//output: "undefined" - pretty reasonable I guess?