How to create constant and a read-only property in JavaScript

In an interview, they often ask you about constant variables and how to create read-only properties in JavaScript. This video explains you that how constants and read-only property can be created in JavaScript.

You can create a constant using the const keyword. The const has statement level scoping as the let keyword.

const foo = 9;

To create a object’s property as read-only use Object.defineProperty. ‘

‘use strict’

var Dog = {

name : ‘tommy’


Object.defineProperty(Dog,’name’,{writable:false}) = “kommy”; // error

Teacher – Dhananjay Kumar , Microsoft MVP, Google GDE.
Blog :
Email : (contact for training or consulting)

Please subscribe to the channel for all latest videos.



Do NOT follow this link or you will be banned from the site!