Values and Types

Learn the primary concepts of types and values used in all programming languages.

We'll cover the following

A value is a piece of information used in a computer program. Values exist in different forms called types. The type of a value determines its role and operations available to it. Every computer language has its own types and values. Let’s look at two of the types available in JavaScript.

Number

A number is a numerical value. Let’s go beyond that though! Like mathematics, you can use integer values (or whole numbers) such as 0, 1, 2, 3, etc, or real numbers with decimals for greater accuracy. Numbers are mainly used for counting. The main operations you can use on numbers are summarized in the following table. All of them produce a numeric result.

Operator Role
+ Addition
- Subtraction
* Multiplication
/ Division

String

A string in JavaScript is text surrounded by quotation marks, such as "This is a string". You can also define strings with a pair of single quotes: 'This is another string'. The best practice for single or double quotes is a whole political thing. Use whichever you like, but don’t mix the two in the same program!

Always remember to close a string with the same type of quotation marks you started it with.

To include special characters in a string, use the \ character (backslash) before the character. For example, type \n to add a new line within a string: "This is\na multiline string".

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy