Skip to content

Instantly share code, notes, and snippets.

@atsushi-kitazawa
Created November 30, 2020 14:56
Show Gist options
  • Save atsushi-kitazawa/bf6d4902ee96740dc10887e0d7b29c23 to your computer and use it in GitHub Desktop.
Save atsushi-kitazawa/bf6d4902ee96740dc10887e0d7b29c23 to your computer and use it in GitHub Desktop.
my javascript study code.
// stdout
var name = "hoge"
console.log("hello "+ name)
// create object
const person = {
name: ['Bob', 'Smith'],
age: 33,
gender: 'male',
bio: function() {
return this.name[0] + ' ' + this.name[1] + ' is ' + this.age + ' years old.'
}
};
console.log(person.name)
console.log(person.name[0])
console.log(person.age)
console.log(person.bio())
console.log(person['name'])
// variable access
var key = 'name'
console.log(person[key])
// constructor function
function Person(name) {
this.name = name;
this.greeting = function() {
return 'Hi! I\'m ' + this.name;
};
}
let person1 = new Person('Bob');
let person2 = new Person('Sarah');
console.log(person1.greeting());
console.log(person2.greeting());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment