# Data Types and Operations

## Data Types

As in other programming languages java script works with some data types. Data types in JavaScript allow us to perform different operation on data. The data types in java script are String, Number, Boolean, Array, Object.

String: A string data type refers to some text values. In JavaScript a string value is place between double or single quotes.

“This is a string” and ‘This also a string’

Number:As you can tell just by reading the name of this data type, it refers to numbers. In JavaScript exists two data types that fall in this category:

Integer: Integers are numbers that numbers with no decimal part for example 6, 20, 456 are examples of integers.

Float: A float data type refers to numbers with decimal for example 3.2, 10.98, 100.99 all this are examples of float data types.

Boolean A Boolean data type in JavaScript refer to literally true or false values.

Array and Object are other data types that will be explain on other sections of this web site. Arrays will be cover on the Loops and Array section and the Object type will be cover in the Ohjects section of this website.

Though an array is an object in JavaScript these two will be treated and explain separately

### JavaScript Variable Types

Type | Purpose | Example |
---|---|---|

boolean | Store true or false | true |

number | a number with or without decimal point | 74.2 |

string | string of text | "San Diego" |

function | a part of a program created using the word function | function{return 23;} |

object | and object such an Array or Date | {name:"Sam",phone:"1788"} |

## Arithtmetic Operators

In JavaScript there are 7 arithmetic operator as shown below

### JavaScript Arithmetic Operators

Operator | Name | Algebraic Expression | JavaScript Expression |
---|---|---|---|

- | Negation | -r | -r |

* | multiplication | vt or v*t or v x t | v * t |

/ | division | x / y | x / y |

% | modulus | r mod s | r % s |

+ | addition | p + q | p + q |

- | subtraction | f - 3 | f - 3 |

= | assignment | s = t | s = t |

Just like in math arithmetic operators help us perform numeric operations when using number data types in JavaScript. Using JavaScript we would obtain the following results.

Example

- 4 + 3 = 7 result Integer
- 4 – 3 = 1 result Integer
- 4 * 3 = 12 result Integer
- 4 / 3 = 1.33 result Float
- 4 % 2 = 0 result Integer

The modulus operator will return the residue of a division as shown in the example above if we divide 4 divided by 2 the residue is 0. What would happen if we try to do “car”+3 in JavaScript in this case is not logical to add an integer and a text because they are not of the same type, so JavaScript will treat the number 3 as a string or as a text “3” then the result will be “car3”. This is called string concatenation. We can concatenate two string by using the + sign.