intermediate object oriented programming
Wed Jul 10 2024 06:27:44 GMT+0000 (Coordinated Universal Time)
Saved by
@NoFox420
#javascript
The Canvas API can be used to create graphics in games using JavaScript and the HTML canvas element.
You will need to use the getContext method which will provide the context for where the graphics will be rendered.
Example Code
canvas.getContext("2d");
The canvas element has a width property which is a positive number that represents the width of the canvas.
Example Code
canvas.width
The innerWidth property is a number that represents the interior width of the browser window.
The innerHeight property is a number that represents the interior height of the browser window.
Here is the syntax for using the destructuring assignment in the parameter list of the arrow function:
Example Code
btn.addEventListener('click', ({ target }) => {
console.log(target);
});
When working with objects where the property name and value are the same, you can use the shorthand property name syntax. This syntax allows you to omit the property value if it is the same as the property name.
Example Code
// using shorthand property name syntax
obj = {
a, b, c
}
The following code is the same as:
Example Code
obj = {
a: a,
b: b,
c: c
}
content_copyCOPY
Comments