ts vs js code example
Example 1: encodeuricomponent js
var set1 = ";,/?:@&=+$";
var set2 = "-_.!~*'()";
var set3 = "#";
var set4 = "ABC abc 123";
console.log(encodeURI(set1));
console.log(encodeURI(set2));
console.log(encodeURI(set3));
console.log(encodeURI(set4));
console.log(encodeURIComponent(set1));
console.log(encodeURIComponent(set2));
console.log(encodeURIComponent(set3));
console.log(encodeURIComponent(set4));
Example 2: typescript vs javascript
JavaScript:
function my_function(my_param) {
console.log('do something');
}
TypeScript:
function my_function(my_param: any) {
console.log('do something');
}
Example 3: typescript vs javascript
They are really almost the same theres not the same param types like
JAVASCRIPT is function myFunction(param)
while typescript is
function myFunction(the_param: something)
Example 4: js defineProperty
var o = {};
Object.defineProperty(o, 'a', {
value: 37,
writable: true,
enumerable: true,
configurable: true
});
var bValue = 38;
Object.defineProperty(o, 'b', {
get() { return bValue; },
set(newValue) { bValue = newValue; },
enumerable: true,
configurable: true
});
o.b;
Object.defineProperty(o, 'conflict', {
value: 0x9f91102,
get() { return 0xdeadbeef; }
});
Example 5: typescript vs javascript
let car = 'BMW';
let age = 15;
let car: string = 'BMW';
let age: number = 15;