DEV Community

Cover image for :(colons), =(equals) and ;(semicolons) in Javascript (Bite-size article)
koshirok096
koshirok096

Posted on • Updated on

:(colons), =(equals) and ;(semicolons) in Javascript (Bite-size article)

Intro

Today I am writing a short article about :(colons), =(equals) and ;(semicolons) in Javascript.

When you use Javascript, you may often use those three operators.

I know how to use them in the codes, but when I'm asked to explain their exact definition, I found I can't explain them clearly.

So I will write about these operators today. For many of you may feel it’s basic, but please take a look if you are interested in :)

Image description

: (colons)

Colons are mainly used to define the properties of an object. JavaScript objects are composed of key/value pairs, with a colon between each key and value.

// example

const person = {
  name: "Terry",
  age: 30,
  occupation: "Engineer"
};

Enter fullscreen mode Exit fullscreen mode

= (equals)

Equals are mainly used to assign a value to a variable. When a value is assigned to a variable, the variable is assigned the value specified on the right side.

// example

let x = 150;
let y = "Hey Guys!";

Enter fullscreen mode Exit fullscreen mode

; (semicolons)

Semicolons are used in JavaScript to indicate the end of statement.

// example

let x = 10;
let y = 20;

Enter fullscreen mode Exit fullscreen mode

Tip: Omit The Semicolon

In JavaScript, a semicolon is generally used to separate statements, but it is also possible to omit the semicolon. But you should use this way carefully because the statement will be automatically ended if you omitting the semicolon.

Normally, using a semicolon to explicitly indicate the end of a statement is recommended to improve code readability. However, in recent JavaScript, semicolons are often omitted in some cases. But anyways, as you write your code, you must be careful to avoid unintended behavior.

Image description

Outro

The topic today is a part of basic knowledges in JS, but I enjoyed to write this article and glad that I got a chance to study about it!

Thank you for reading :)

Top comments (0)