JavaScript中的const

const (const)

Like other programming languages, JavaScript also provide the feature to create constants, we can make any identifier as constant by using the "const".

與其他編程語言一樣,JavaScript也提供了創建常量的功能,我們可以使用“ const”將任何標識符設為常量。

"const" is a keyword in JavaScript and it makes an identifier constant.

“ const”是JavaScript中的關鍵字,它使標識符恒定。

Syntax:

句法:

const identifier_name = value;

Points to remember:

要記住的要點:

  • While creating a constant, a value should be assigned.

    創建常數時,應分配一個值。

  • A constant’s value cannot be changed.

    常量的值不能更改。

Error

錯誤

If we try to change the value of a constant following type error throws:

如果我們嘗試更改以下常量的值,則會引發類型錯誤:

TypeError: Assignment to constant variable.

Example:

例:

<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>		
const url = "www.example.com";
const port_no = 25;
//printing...
document.write("url: " + url + "<br>");
document.write("port_no: " + port_no + "<br>");
//if you will try to change the value
//it will not be changed
try{
port_no = 21;		
}
catch(err){
document.write(err + "<br>");
}
</script>
</body>
</html>

Output

輸出量

url: www.example.com
port_no: 25
TypeError: Assignment to constant variable.

翻譯自: https://www.includehelp.com/code-snippets/const-in-javascript.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540763.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540763.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540763.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

無法從ftp服務器上復制文件格式,ftp服務器上復制不了文件格式

ftp服務器上復制不了文件格式 內容精選換一換本版本提供dump_data_conversion.pyc腳本&#xff0c;實現dump數據文件與numpy文件格式互轉功能&#xff0c;具體命令行格式如下&#xff1a;-type&#xff1a;數據類型&#xff0c;必選參數 。參數值選項&#xff1a;quant&#xf…

華大基因茅矛:云計算讓精準醫療走進生活

2016年是“十三五”的開局之年&#xff0c;也是中國醫療衛生行業的關鍵一年。現在看來&#xff0c;也會是醫療行業和以大數據為代表的信息技術相互融合發展之年。今年4月&#xff0c;國務院辦公廳印發《深化醫藥衛生體制改革2016年重點工作任務》&#xff0c;其中不僅談到了要加…

Python Pandas –操作

Pandas support very useful operations which are illustrated below, 熊貓支持非常有用的操作&#xff0c;如下所示&#xff0c; Consider the below dataFrame, 考慮下面的dataFrame&#xff0c; import numpy as npimport pandas as pddf pd.DataFrame({col1: [1, 2, 3,…

有道詞典總顯示無法連接服務器,有道詞典無法聯網提示網絡已斷開該怎么辦

人們使用電腦時候最不想看到的事情之一就是上不了網了&#xff0c;無論是工作還是玩游戲時候都很不爽。電腦能正常上網&#xff0c;但是有道詞典始終無法聯網。這是怎么回事呢?下面一起看看!方法步驟1、我是win8的系統。有道詞典無法聯網后&#xff0c;我在網上查了一下方法&a…

ajax+lazyload時lazyload失效問題及解決

最近寫公司的項目的時候遇到一個關于圖片加載的問題&#xff0c;所做的頁面是一個商城的商品列表頁&#xff0c;其中需要顯示商品圖片&#xff0c;名稱等信息&#xff0c;因為商品列表可能會很長&#xff0c;所以其中圖片需要滑到可以顯示的區域再進行加載。 首先我的圖片加載插…

手游pubg mobile服務器正在維護,PUBG Mobile Download Failed怎么解決

《PUBG Mobile》國際服出現下載失敗的情況&#xff0c;你將會收到“Download Failed”提示&#xff0c;你就需要按照下述的方法去解決該問題。注意&#xff1a;如果下載不了 請復制瀏覽器上的鏈接 https:/http://pic.81857.netownloads.gradle.orghttp://pic.81857.netistribut…

Python自動化運維之常用模塊—logging

在現實生活中&#xff0c;記錄日志非常重要。銀行轉賬時會有轉賬記錄&#xff1b;如果有出現什么問題&#xff0c;人們可以通過日志數據來搞清楚到底發生了什么。 對于系統開發、調試以及運行&#xff0c;記錄日志都是同樣的重要。如果沒有日志記錄&#xff0c;程序崩潰時你…

Sys.WORD_SIZE Julia中的常量

Julia| Sys.WORD_SIZE常數 (Julia | Sys.WORD_SIZE Constant) Sys.WORD_SIZE is a constant of the Int64 type in Julia programming language, it is used to get the standard word size of the current system. Sys.WORD_SIZE是Julia編程語言中Int64類型的常量&#xff0c;…

ftp服務器如何配置多個文件夾,ftp服務器如何配置多個文件夾

ftp服務器如何配置多個文件夾 內容精選換一換Model File:模型文件。單擊右側的文件夾圖標&#xff0c;在后臺服務器sample所在路徑(工程目錄/run/out/test_data/model)選擇需要轉化的模型對應的*.prototxt文件&#xff0c;并上傳。Weight File:權重文件。請自行從https://obs-m…

scala 方法調用_Scala中的方法調用

scala 方法調用Scala方法調用 (Scala Method Invocation) Method invocation is the legal and correct technique to call a method in Scala programming language. The methods of a class are usually accessed by using two methods. 方法調用是用Scala編程語言調用方法的…

docker lnmp php

使用 Docker 構建 LNMP 環境https://segmentfault.com/a/1190000008833012Docker 快速上手指南https://segmentfault.com/a/1190000008822648#articleHeader44

根據分類id找出父類id

2019獨角獸企業重金招聘Python工程師標準>>> 數組格式要求 id > pid $columns [ 1 > 0, 10 > 1, 200 > 10 ]; public function getP($columns,$pid) { 模擬 $pid 200; $arr $columns; while($arr[$pid]) { …

不穩定學習器適合做基分類器_分類穩定性

不穩定學習器適合做基分類器什么是分類&#xff1f; (What is sorting?) It means to arrange data elements in increasing or decreasing order. There are many algorithms to do so like mergesort, quicksort, counting sort etc but there are pros and cons of each al…

JavaScript基礎學習--05自定義屬性、索引值

Demos&#xff1a; https://github.com/jiangheyan/JavaScriptBase 一、自定義屬性1、讀寫操作<input abc"123" type"button" value"按鈕" />//讀寫&#xff1a; var aBtn document.getElementsByTagName(input); aBtn[0].abc 456; 2、…

有線電視pcr是什么意思_有線電視的完整形式是什么?

有線電視pcr是什么意思有線電視&#xff1a;社區訪問電視 (CATV: Community Access Television) CATV is an abbreviation of "Community Access Television". CATV是“社區訪問電視”的縮寫 。 It is also known as Public Access Television, which is a type of …

桶分類 算法_桶分類算法

桶分類 算法桶分類 (Bucket Sort) Bucket sort is a sorting technique in which array is partitioned into the buckets. By this, each bucket will be sorted individually, by using some another sorting algorithm such as insertion sort. This sorting technique assu…

百度之星初賽(A)——T5

今夕何夕 Problem Description今天是2017年8月6日&#xff0c;農歷閏六月十五。 小度獨自憑欄&#xff0c;望著一輪圓月&#xff0c;發出了“今夕何夕&#xff0c;見此良人”的寂寞感慨。 為了排遣郁結&#xff0c;它決定思考一個數學問題&#xff1a;接下來最近的哪一年里的同…

mycat 不得不說的緣分

1&#xff0c;愕然回首。它在燈火闌珊處關于mysql集群中間件。曾經寫在應用程序里面&#xff0c;由開發者實現&#xff0c;在配置文件中面寫多個數據源&#xff0c;寫庫一個數據源&#xff0c;讀庫一個數據源&#xff0c;笨拙不高效&#xff0c;由于程序猿的差異化。效果并非特…

python創建空元組_用Python創建空元組

python創建空元組Python | 空元組 (Python | empty tuple) In python, we can also create a tuple without having any element. An empty tuple is created using a pair of round brackets, (). 在python中&#xff0c;我們也可以創建一個沒有任何元素的元組 。 使用一對圓括…

共享馬扎的火爆,原來是一場營銷!

如今&#xff0c;人們的生活仿佛已經被“共享化”&#xff1a;上班有共享單車、睡覺有共享床鋪、商場有共享充電寶、去機場有共享巴士……好像除了男女朋友是自己的&#xff0c;其他都要共享了&#xff01;哎&#xff0c;不對&#xff01;前些日子&#xff0c;竟然還真有了共享…