# Summary

A recap of how JavaScript differs from Java, and where to go further.

Apprentice · JavaScript · Updated November 16, 2026

By Gregor Dzierzon

JavaScript and Java share some similarities, but it is best to view JavaScript as a new programming language so that you don't confuse the nuances of each language with each other.

JavaScript was initially designed to be used in browsers, but it has evolved to a robust full stack development language that can also run as stand-alone applications on desktops and web servers. We will focus on JavaScript in the browser for the rest of this course.

When you want to go further, [JavaScript in Depth](https://www.ask-codey.com/courses/javascript-in-depth) teaches the language from the start, with a practice box in every lesson.

## Do it: list the snacks in stock

The snack stand's menu shows only the snacks it still has, each as a line of text with its name and price. This one function uses what the chapter taught: an object for each snack, a function, and array methods.

The function gets one value:

- `snacks`: an array of snack objects. Each has three properties: `name` (`'Trail Mix'`), `price` in whole dollars (`4`) and `stock`, how many are left (`12`).

For example:

```javascript
menuLines([
    { name: 'Trail Mix', price: 4, stock: 12 },
    { name: 'Apple Chips', price: 3, stock: 0 },
    { name: 'Granola Bar', price: 2, stock: 5 }
])
```

Apple Chips has a stock of `0`, so it's left out. The function returns:

```javascript
['Trail Mix: $4', 'Granola Bar: $2']
```

**Your job:** write the function `menuLines(snacks)` so it returns a new array of text.

- Keep the snacks whose `stock` is more than `0`, in the order they came.
- Turn each one into `'<name>: $<price>'`, such as `'Trail Mix: $4'`.
- When no snack is in stock, or `snacks` is empty, return an empty array, `[]`.

Practiced live on the lesson page: write the JavaScript right there and check it.

## Sources

Mozilla's MDN Web Docs, the reference most JavaScript developers keep open:

- [JavaScript Guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide)
- [JavaScript data types and data structures](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures)
- [Numbers and dates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates)
- [Text formatting](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Text_formatting)

Source: https://www.ask-codey.com/lessons/java-vs-javascript-summary
