JavaScript has several constants

青灯夜游
Release: 2021-10-20 12:01:22
Original
3979 people have browsed it

JavaScript has 5 types of constants, which are: 1. Integer constants, which are actually positive numbers; 2. Real constants, which are actually decimals; 3. String constants, which are actually using single or double quotes. The enclosed content; 4. Boolean constant; 5. Custom constant, defined using the statement "const constant name = constant value;".

JavaScript has several constants

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

What are constants

  • Constants represent some fixed data

  • In real life Human gender can actually be regarded as constants. If you are born a boy, you will be a boy throughout your life. If you are born a girl, you will be a girl throughout your life.

Classification of constants in JavaScript

  • Integer constants
    • Integer constants are actually positive numbers. Any integer written in JavaScript is an integer constant
    • 1 / 666 / 99
  • Real constants
    • Real constants are actually decimal, which can be used casually in JavaScript Writing a decimal is a real constant
    • 3.14 / 6.66
  • String constant
    • String constant is actually used Single quotation marks or double quotation marksenclose the content, we call it a string constant
    • 'a'
    • 'abc'
    • “1”
    • “BNTang”
    • Note: No matter how many characters are enclosed in single quotes or double quotes, in JavaScript String constant
  • Boolean constant
      Boolean constant is actually
    • true or false, in In JavaScript, true and false are used to express
    • In JavaScript, Boolean constants have only two values, true (true) or false (false)
  • Custom constants
      Newly added in
    • ES6
    • const constant name = constant take Value;
const NUM = 666;
Copy after login
// NUM = 888; //尝试修改NUM这个常量的取值,会发现报错了,常量一旦定义就不能再去改变值了
Copy after login
console.log(NUM);
Copy after login
[Recommended learning:

javascript advanced tutorial]

The above is the detailed content of JavaScript has several constants. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template