I am exploring and learning programming languages that share similarities with JavaScript.
In this repository, I am attempting to learn every programming language that has behavior and capabilities similar to JavaScript, like:
let something = "foo";
console.log(`something: ${something}`);
something = 123;
console.log(`something: ${something}`);
something = true;
console.log(`something: ${something}`);
something = null;
console.log(`something: ${something}`);
something = [1, 2, 3];
console.log(`something: ${something}`);
something = { "foo": "bar" };
console.log(`something: ${something}`);
type Any interface{}
function getModifiedIndentLevel() {
let indentLevel = 0;
function changeIndentLevel() {
indentLevel += 1;
if (indentLevel < 5) changeIndentLevel();
return indentLevel;
}
return changeIndentLevel();
}
console.log(`getModifiedIndentLevel(): ${getModifiedIndentLevel()}`);
function createNewGame(initialCredit) {
let currentCredit = initialCredit;
console.log(`initial credit: ${initialCredit}`);
return function () {
currentCredit -= 1;
if (currentCredit === 0) {
console.log("not enough credits");
return;
}
console.log(`playing game, ${currentCredit} credit(s) remaining`);
};
}
const playGame = createNewGame(3);
playGame();
playGame();
playGame();
const myObject = {
"my_string": "foo",
"my_number": 123,
"my_bool": true,
"my_null": null,
"my_array": [1, 2, 3],
"my_object": {
"foo": "bar"
}
};
console.log(`myObject: ${myObject}`);
const myArray = ["foo", 123, true, null, [1, 2, 3], { "foo": "bar" }];
console.log(`myArray: ${myArray}`);
function sayHello(callbackFunction) {
console.log("hello");
callbackFunction();
}
function sayHowAreYou() {
console.log("how are you?");
}
sayHello(sayHowAreYou);
sayHello(function () {
console.log("how are you?");
});
function multiply(a) {
return function (b) {
return (a * b);
};
}
const multiplyBy2 = multiply(2);
const multiplyBy2Result = multiplyBy2(10);
console.log(`multiplyBy2Result: ${multiplyBy2Result}`);
const getRectangleAreaV1 = function (rectangleWidth, rectangleLength) {
return (rectangleWidth * rectangleLength);
};
console.log(`getRectangleAreaV1(7, 5): ${getRectangleAreaV1(7, 5)}`);
const getRectangleAreaV2 = (rectangleWidth, rectangleLength) => {
return (rectangleWidth * rectangleLength);
};
console.log(`getRectangleAreaV2(7, 5): ${getRectangleAreaV2(7, 5)}`);
const getRectangleAreaV3 = (rectangleWidth, rectangleLength) => (rectangleWidth * rectangleLength);
console.log(`getRectangleAreaV3(7, 5): ${getRectangleAreaV3(7, 5)}`);
const myArray2 = [
function (a, b) {
return (a * b);
},
"foo",
123,
true,
null,
[1, 2, 3],
{ "foo": "bar" }
];
console.log(`myArray2[0](7, 5): ${myArray2[0](7, 5)}`);
const myObject2 = {
"my_function": function (a, b) {
return (a * b);
},
"my_string": "foo",
"my_number": 123,
"my_bool": true,
"my_null": null,
"my_array": [1, 2, 3],
"my_object": {
"foo": "bar"
}
}
console.log(`myObject2["my_function"](7, 5): ${myObject2["my_function"](7, 5)}`);
HOW TO RUN THE CODES:
to run JavaScript code:
to run Python code:
to run PHP code:
to run Go code:
to run Perl code:
to run Julia code:
to run Lua code:
to run Ruby code:
to run R code:
to compile and run Kotlin code:
to compile and run Swift code:
to run Dart code:
to compile and run Visual Basic (.NET) code:
to compile and run C# code:
to run Matlab code:
to run Octave code:
to run Wolfram code:
to run Raku code:
to run Scala code:
https://github.com/willyhorizont https://github.com/willyhorizont/learn_programming_languages_with_javascript