some doc fixes

This commit is contained in:
Tom Ball 2016-07-25 17:00:51 -04:00
parent ca3cd1de22
commit c4139a862f
4 changed files with 11 additions and 30 deletions

View File

@ -1,27 +1 @@
# JavaScript and TypeScript # 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.

View File

@ -1,8 +1,11 @@
## Operators ## Operators
The following JavaScript operators are supported for the micro:bit. 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. 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. This also is true when simulating in the browser.
### ~
# Assignment, arithmetic and bitwise # Assignment, arithmetic and bitwise
@ -22,6 +25,6 @@ This also is true when simulating in the browser.
* strings, with a few common methods * strings, with a few common methods
* [string templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) (`` `x is ${x}` ``) * [string templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) (`` `x is ${x}` ``)
### ~button /js/controlflow ### ~button /js/statements
NEXT: Control Flow NEXT: Statements
### ~ ### ~

View File

@ -42,11 +42,15 @@ followed by a call to `showNumber` that will never execute:
```typescript ```typescript
while(true) ; basic.showNumber(1); 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. 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: If you really want an empty statement, you need to use curly braces to delimit an empty statement block:
```typescript ```typescript
while(true) { } basic.showNumber(1); while(true) { } basic.showNumber(1);
``` ```
### ~
[Read more](http://inimino.org/~inimino/blog/javascript_semicolons) about semicolons in JavaScript. [Read more](http://inimino.org/~inimino/blog/javascript_semicolons) about semicolons in JavaScript.

View File

@ -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. 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. In other words, they have the same scoping rules as `let`, but you can't re-assign to them.
### ~button /js/expressions ### ~button /js/operators
NEXT: Expressions NEXT: Operators
### ~ ### ~