Skip to content

Instantly share code, notes, and snippets.

@nezahualcoyotl
Created May 26, 2021 23:15
Show Gist options
  • Save nezahualcoyotl/327bce4cb199a73da8f263ae9827ea02 to your computer and use it in GitHub Desktop.
Save nezahualcoyotl/327bce4cb199a73da8f263ae9827ea02 to your computer and use it in GitHub Desktop.
Basic stuff I've been doing wrong in javascript
/* is a great practice to use strict to
force all variables to be declared */
"use strict";
// use const to declare important unchanging variables
const pi = 3.141592653589793;
// declare the damn thing with let, not just var
let greeting = "Hello";
// concatenate strings using inverted accent mark (is that even a thing?)
console.log(`Hey, ${greeting}`);
// a cool way to swtich from true to false
let is_paid = true;
is_paid = !is_paid;
// how to create a simple object
let person = {
firstName: ‘Damian’,
lastName: ‘Medina’
};
// is a good practice to always use === instead of ==
console.log('1' === 1); // false
// how to embed functions within objects
let person = {
name: ‘Damian’,
age: 32,
showName: function() {
alert(this.name);
}
};
person.showAlert();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment