Hello JavaScript!

Sunday, Jan 5, 2020
JavaScript

I was a little bit hesitant to throw JavaScript into the mix at this time (while learning C). Primary concerns were:

Well the problem is that I am also learning about algorithms concurrently and apparently more work is needed in C as there are no in-built data structures (besides the bare bones fixed-length array). It will take me some time to learn to create custom data structures in C. JavaScript however has implementation of dynamic arrays that I can start using to learn algorithms. The concerns I mentioned earlier are not that big since:

Here we go

console.log("Hello, JavaScript!");
console.log();

// function call
greet("World");
console.log();

// any variable type defined using var
var foo = 5; 
var bar = "Hello";

// arrays
var nums = [1, 2, 3, 4];
console.log(foo, foo * foo, Math.sqrt(foo));

console.log();
foo++; // var incrementation
console.log(foo, bar, nums);
console.log();

// conditional
if (foo > 5 && bar == "Hello")
    console.log(bar, foo);
console.log("Number  Square");
console.log();

// loop
for (var i = 0; i < nums.length; i++)
    console.log(nums[i],"       ", nums[i] * nums[i]);

// functions
function greet(name)
{
    console.log("Hello, "+ name + "!");
    console.log("How are you today?");
}

Output

Hello, JavaScript!

Hello, World!
How are you today?

5 25 2.23606797749979

6 Hello [ 1, 2, 3, 4 ]

Hello 6
Number  Square

1         1
2         4
3         9
4         16