Hour 2 : JS

Continuing learned using boolean values, conditional statements, switch case and use of functions. Everything goes on like we might have learned in some other language. Encountered only a new operator category called the strict equality operator and strict inequality operator.

Strict equality operator uses === instead of the normal == for the equality operator. So is the case for strict inequality operator which uses !== and not !=. These strict comparison operators compare the types of values being compared unlike the normal comparison operator that coerces the data type and checks only the values. No more differences than standard practices of these operators and conditionals!

Hour 1 : JS

Having not used JS even to a novice level, I had planned to learn it and create something substantial. And today was the first day to executing the plan. I will brief out the things I learned in the sequence on a map.

undefined, null, boolean, string, number, symbol and object are the 7 data types. Variables are declared with var keyword and accessing the value of a variable that has not been initialised returns an error of undefined type or sometimes a NaN. Names of variables can have alphanumeric characters, $ or _ but not a space or cannot start with a number. JS is case-sensitive. Arithmetic operations work on universal principles, so nothing new there.

Since double quotes are used to encase string literals, they have to be escaped when one wants them to be a part of the literal. However, this can be avoided by using single quotes to enclose the literal and vice-versa. Square brackets with zero based indexing is used to access characters in a string. Strings in JS are immutable and hence have to be defined all over instead of manipulating only the characters one wishes to modify. For instance,

var myStr = "Jello World";
myStr = "Hello World"; // This has to be fixed all over instead of accessing the first character using myStr[0].

Multi-dimensional arrays can be created by nesting several elements as part of a single element. An example:

var myArr = [[1, 2], [3, 4]];
var a = myArr[1,1]; //This assigns value of 4 to variable <em>a</em>.

Few operations to update arrays are:

  1. push() – Appends data to end of the array.
  2. pop() – Pops an element from end of the array.
  3. shift() – Pops first element of the array.
  4. unshift() – Adds element in the beginning of the array.

function keyword is used to define a function which is called via its name and arguments, if it requires any. Variables defined inside the function have local scope and those outside have the global scope. The value of the global variable is overridden by the local variable, that is a rule, ofcourse when both have same names. Global variables can be defined without the keyword var which is not considered a good practice because it comes with consequences which I have to determine yet.

This is all I grabbed in the 1 hour today, à bientôt!