Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

declaring a variable with colon in JavaScript

Hi right now i'm learning JavaScript. There is a confusion with some JavaScript I just found. This is the source code

import type { OptionsType } from 'Types'

const theme: OptionsType = {
  title: 'Lawton',
  baseFontSize: '16px',
  baseLineHeight: 1.5
}

In the code, the const variable is declared with ":"

What does ":" mean in the expression ?

Is it equivalent with

const theme = OptionsType = { title: 'Lawton' }
like image 403
Semooze Avatar asked Oct 26 '25 11:10

Semooze


1 Answers

What does ":" mean in the expression ?

This is FlowType. Checkout the docs on the annotation: https://flow.org/en/docs/getting-started/

More

This is not TypeScript as import type is a flow thing: https://flow.org/en/docs/types/modules/#importing-and-exporting-types-a-classtoc-idtoc-importing-and-exporting-types-hreftoc-importing-and-exporting-typesa

like image 71
basarat Avatar answered Oct 28 '25 03:10

basarat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!