some doc fixes
This commit is contained in:
parent
ca3cd1de22
commit
c4139a862f
@ -1,27 +1 @@
|
||||
# JavaScript and TypeScript
|
||||
|
||||
You can write micro:bit programs in a subset of [TypeScript](https://www.typescriptlang.org), a superset of JavaScript.
|
||||
Many micro:bit programs, especially at the beginner's level, are just plain JavaScript. TypeScript introduces class-based
|
||||
object-oriented programming, such as:
|
||||
|
||||
```typescript
|
||||
class Greeter {
|
||||
greeting: string;
|
||||
constructor(message: string) {
|
||||
this.greeting = message;
|
||||
}
|
||||
greet() {
|
||||
return "Hello, " + this.greeting;
|
||||
}
|
||||
}
|
||||
|
||||
let greeter = new Greeter("world");
|
||||
basic.showString(greeter.greet())
|
||||
```
|
||||
|
||||
This site is meant for teaching programming first, and JavaScript second. For this
|
||||
reason, we have stayed away from concepts that are specific to JavaScript (for
|
||||
example, prototype inheritance), and instead focused on ones common to most
|
||||
modern programming languages (lexically scoped variables, functions, classes).
|
||||
We leverage TypeScript's [type inference](/js/inference) so that
|
||||
students need not specify types when clear from context.
|
||||
|
@ -1,8 +1,11 @@
|
||||
## Operators
|
||||
|
||||
The following JavaScript operators are supported for the micro:bit.
|
||||
|
||||
### ~hint
|
||||
Note that for the micro:bit all arithmetic is performed on integers, rather than floating point.
|
||||
This also is true when simulating in the browser.
|
||||
### ~
|
||||
|
||||
# Assignment, arithmetic and bitwise
|
||||
|
||||
@ -22,6 +25,6 @@ This also is true when simulating in the browser.
|
||||
* strings, with a few common methods
|
||||
* [string templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) (`` `x is ${x}` ``)
|
||||
|
||||
### ~button /js/controlflow
|
||||
NEXT: Control Flow
|
||||
### ~button /js/statements
|
||||
NEXT: Statements
|
||||
### ~
|
@ -42,11 +42,15 @@ followed by a call to `showNumber` that will never execute:
|
||||
```typescript
|
||||
while(true) ; basic.showNumber(1);
|
||||
```
|
||||
|
||||
|
||||
### ~hint
|
||||
For the micro:bit, we don't allow a program to contain an empty statement, such as shown above.
|
||||
If you really want an empty statement, you need to use curly braces to delimit an empty statement block:
|
||||
```typescript
|
||||
while(true) { } basic.showNumber(1);
|
||||
```
|
||||
### ~
|
||||
|
||||
[Read more](http://inimino.org/~inimino/blog/javascript_semicolons) about semicolons in JavaScript.
|
||||
|
||||
|
@ -116,6 +116,6 @@ const numLivesForCat = 9;
|
||||
They are like `let` declarations but, as their name implies, their value cannot be changed once they are bound.
|
||||
In other words, they have the same scoping rules as `let`, but you can't re-assign to them.
|
||||
|
||||
### ~button /js/expressions
|
||||
NEXT: Expressions
|
||||
### ~button /js/operators
|
||||
NEXT: Operators
|
||||
### ~
|
Loading…
Reference in New Issue
Block a user