Expressions and Output
Intro to Expressions and Output
The first thing any programmer needs to learn is how to see the results of their
code. In JavaScript and TypeScript, we use
console.log() to print values to
the terminal.console.log('Hello, World!')
When you run this code in any JavaScript environment (like the browser console or in Node.js), you'll see
Hello, World! printed in your terminal.Running Your Code
You can save this code in a file and then run it with Node like so:
node index.ts
Node.js will execute your code and show any
console.log output in the
terminal.Expressions
An expression is any piece of code that produces a value. Here are some
examples:
// String expressions
'Hello'
'Hello' + ' World'
// Number expressions
42
10 + 5
100 / 4
You can pass any expression to
console.log() to see its value:console.log(10 + 5) // Prints: 15
console.log('Hello' + ' World') // Prints: Hello World
console.log() is your best friend when learning to code. Use it liberally to
understand what your code is doing!In this exercise, you'll learn to use
console.log() to output different types
of expressions.