Being a Web Developer - Programming Languages
Tags: html, css, javascript, typescript
Published: 2022-07-18 05:57:54

## What are programming languages?

Programming languages are a way for humans and computers to communicate. People read code many, many multiples of times more than they write it - so developers create programming languages which are good at solving particular problems with a small amount of code. Here's an example using JavaScript:

```
var name = "Danger"
console.log("Hello, " + name)
```

The first line makes a variable (effectively a box you can store other things in) and then the second line outputs text to the console (for example DOS, or the terminal) "Hello, Danger".

JavaScript is designed to work as a scripting language, which means the code starts at the top of the file and then goes through line by line downwards running that code. To provide some contrast, here is the same behavior in Java, which is built with different language constraints:

```
class Main {
  public static void main(String[] args) {
    String name = "Danger";
    System.out.println("Hello, " + name);
  }
}
```

These two code samples do the same thing, however the Java version comes with a lot of words that aren't necessarily about telling the computer exactly what to do, e.g. class Main {, public static void main(String[] args) {, and two extra &rbrace;s. It also has semi-colons at the end of some lines. Neither of these programming languages are wrong, Java however, is aimed at building different things from JavaScript, and these extra bits of code make sense within the constraints of building a Java app.

```
// JavaScript
var name = "Danger"

// Java
String name = "Danger";
```

Both of these lines declare variables called name which contain the value "Danger".

In JavaScript you use the abbreviation var to declare a variable. Meanwhile, in Java you need to say what kind of data the variable contains. In this case the variable contains a String. (A string is a programming term for a collection of characters. They "look like this". This 5m video is a good primer if you want to learn more.)

Both of these variables contain a string, but the difference is that in Java the variable can only ever contain a string, because that's what we said when we created the variable. In JS, the variable can change to be anything, like a number, or a list of dates.

To illustrate:

```
// Before in JS
var name = "Danger"
// Also OK
var name = 1
var name = false
var name = ["2018-02-03", "2019-01-12"]

// Before in Java
String name = "Danger";
// Not OK, the code wouldn't be accepted by Java
String name = 1;
String name = false
String name = new String[]{"2018-02-03", "2019-01-12"};
```

These trade-offs make sense in the context for which these languages were built back in 1995. JavaScript was originally designed to be a small programming language which handled simple interactions on websites. Java on the other hand was built specifically to make complex apps which could run on any computer. They expected to be used to build codebases of different scales, so the language required programmers write different types of code.

Java required programmers to be more explicit with the values of their variables because the programs they expected people to build were more complex. While JavaScript opted for ease of reading by omitting information about the specifics, and expected codebases to be significantly smaller.

---
## Paul Ishaili C.
`Traditional Creative Director, Software Engineer and Tech Writer`