2018-10-10 18:03:03 -04:00
---
id: bd7123c9c441eddfaeb4bdef
2021-02-06 04:42:36 +00:00
title: Comment Your JavaScript Code
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-04-29 18:29:13 +08:00
videoUrl: 'https://scrimba.com/c/c7ynnTp'
forumTopicId: 16783
2021-01-13 03:31:00 +01:00
dashedName: comment-your-javascript-code
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
Comments are lines of code that JavaScript will intentionally ignore. Comments are a great way to leave notes to yourself and to other people who will later need to figure out what that code does.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
There are two ways to write comments in JavaScript:
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
Using `//` will tell JavaScript to ignore the remainder of the text on the current line:
2020-04-29 18:29:13 +08:00
```js
// This is an in-line comment.
```
2021-02-06 04:42:36 +00:00
You can make a multi-line comment beginning with `/*` and ending with `*/` :
2020-04-29 18:29:13 +08:00
```js
/* This is a
multi-line comment */
```
2021-02-06 04:42:36 +00:00
**Best Practice**
As you write code, you should regularly add comments to clarify the function of parts of your code. Good commenting can help communicate the intent of your code—both for others *and* for your future self.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Try creating one of each type of comment.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
You should create a `//` style comment that contains at least five letters.
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(code.match(/(\/\/)...../g));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
You should create a `/* */` style comment that contains at least five letters.
2020-04-29 18:29:13 +08:00
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(code.match(/(\/\*)([^\/]{5,})(?=\*\/)/gm));
2018-10-10 18:03:03 -04:00
```
2020-04-29 18:29:13 +08:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
// Fake Comment
/* Another Comment */
```