Skip to content

Instantly share code, notes, and snippets.

@Irwin1985
Last active January 16, 2023 21:28
Show Gist options
  • Save Irwin1985/0dacae605b0ca27a6dbdd153e81a5557 to your computer and use it in GitHub Desktop.
Save Irwin1985/0dacae605b0ca27a6dbdd153e81a5557 to your computer and use it in GitHub Desktop.
// comentario sencillo
/*
Comentario
múltiple
*/
// literales
123 // enteros
"hola" // string
true // boolean true
false // boolean false
// declaración de variables
var x = 10;
// control de flujo
// if
if (a + b > 10) {
print("mayor");
} else {
print("menor");
}
// switch
switch (letra) {
case 'a':
print("a");
break;
case 'b':
print("b");
break;
default:
print("unknown");
break;
}
// iterators
var x = 10;
while (x > 0) {
print(x);
x--;
}
// project modulation
module Math
func abs(value) {
if (value < 0) {
return -value;
}
return value;
}
// import module
import Math
print(Math.abs(-5)); // 5
// class
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
calc() {
return this.x + this.y;
}
}
var p = new Point(10 , 20);
print(p.calc()); // 30
// function
fn add(x, y) {
return x + y;
}
// IILE: inmediate invoke lambda expressoin
fn(x) => ( x * x;)(10); // 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment