Values in JavaScript

JavaScript has various value types including strings, numbers, booleans, etc. Here are a few basic examples.

// Strings, which can be added together with '+'
console.log("java" + "script")

// Numbers (JavaScript doesn't distinguish between integers and floats)
console.log("1+1 =", 1 + 1)
console.log("7.0/3.0 =", 7.0 / 3.0)

// Booleans, with boolean operators as you'd expect
console.log(true && false)
console.log(true || false)
console.log(!true)

To run the program, save it as values.js and use node:

$ node values.js
javascript
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false

In JavaScript, all numbers are floating-point values, so there’s no distinction between integers and floats as in some other languages. The arithmetic operations work similarly, but keep in mind that due to the nature of floating-point arithmetic, some operations might produce slightly different results compared to languages with separate integer types.

Boolean operations in JavaScript work just like in many other programming languages, with && for AND, || for OR, and ! for NOT.

JavaScript uses console.log() for printing to the console, which is analogous to fmt.Println() in other languages.