﻿(() => {
	let output: string = "";

	// Variables now have types
	// number
	// string
	// bool
	// array
	let someNumber: number;
	let someString: string = "fred";
	let someBool: boolean = true;
	let numArray: number[] = [1, 2, 3];
	var stringArray: string[];          // Note: you must create array before using it i.e. = []
	let someValue: any;                 // Accept any value
	let someObj: { x: number, y: number };  // Object literal with x and y numbers

	//someNumber = "22"; won't compile!!

	// Must create array e.g. stringArray = []; before using it!!
	stringArray = ["Apple", "Pear"];        // Create and initialise array here!!
	stringArray[2] = "Orange";

	// Prints ApplePearOrange
	for (let i in stringArray)
	{
		output = output + stringArray[i] + "\n";
	}
	output += "\n";

	someValue = 2;
	someValue = "Fred";

	someObj = { x: 2, y: 3 };

	// Also have enums
	enum Fruit { Apple, Pear, Orange };     // Start with 0 but can change e.g. Apple=1 to start numbering from 1 
	let favFruit: Fruit = Fruit.Apple;

	// Destructuring
	// Automatic assignments

	// Use destructuring with arrays
	let input: string[] = ["One", "Two", "Threee"];
	let [num1, num2, num3] = input;
	output += "First number is " + num1 + "\n";
	output += "Second number is " + num2 + "\n";
	output += "Third number is " + num3 + "\n";

	// Use destructuring with objects
	let {x, y} = someObj;
	output += "X is " + x + "\n";    // x = obj.x
	output += "Y is " + y + "\n";    // y = obj.y

	console.log(output);
})();