TypeScript Tutorial
TypeScript Output
console.log sends text to the console. That is how every first program talks back.
console.log writes to the console
console.log is the standard way to print. You pass it a value, or several values. After the program runs, you see those characters in the console — on StudyGrid, that is the output pane under the editor. This is TypeScript’s equivalent of C++ cout.
Example
console.log("Hello from console.log");Open examples with Try it in TypeScript. That is /typescript/try: a tsc compile-and-run editor.
Pass several values
One call can take many arguments. StudyGrid joins them with a space, the same way Node does. Mixing strings and numbers is normal. You do not chain << the way C++ does.
Example
console.log("Score:", 12, "points");
console.log(3, "plus", 4, "is", 3 + 4);The order is left to right. First the label, then the number, then more text. You can also build one string with+ and pass that single value.
Each call starts a new line
console.log ends with a newline. The next call prints on the next line. To print two lines from one string, put \n inside the quotes.
Example
console.log("first line");
console.log("second line");
console.log("third line\nfourth line");Arguments in one call stay on the same line. Two separate console.log calls become two lines. Forget that and you split a sentence that should have stayed together.
Numbers, booleans, and strings
console.log prints integers, floating-point values, booleans, and quoted text. Aboolean prints as the words true and false, not as 1 and0 the way C++ cout often does.
Example
const count: number = 7;
const price: number = 2.5;
const ready: boolean = true;
console.log(count);
console.log(price);
console.log(ready);
console.log("done");Spaces between arguments are automatic
Separate arguments get a space between them. If you concatenate with + instead, you must put the spaces in yourself. "Hi" + "there" is Hithere.
| Code | What you see |
|---|---|
console.log(2, 5); | 2 5 |
console.log(2 + "" + 5); | 25 |
console.log("n=" + 3); | n=3 |
Nothing to include
C++ needs <iostream> before cout. TypeScript does not. console is there from the start. Change a printed value and compile again.
Next: comments, so you can leave notes next to the lines that print.