Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

var or const in javascript

// var declares a variable, meaning its value will vary. 
// const declares a constant, meaning its value will remain 
// consistant and not change. 
// If your variable changes throughout the program or website, 
// declare it using a var statement. 
// Otherwise, if its value does not change, declare it using 
// a const statement. 

const myConst='A const does not change.';

var myVar='A var does change.';

var myVar=2;
Comment

javascript const

const b = 1; // this variable unique and can't change it. 
Comment

const { something} javascript

const obj = {
  name: "Fred",
  age: 42,
  id: 1
}

//simple destructuring
const { name } = obj;
console.log("name", name);

//assigning multiple variables at one time
const { age, id } = obj;
console.log("age", age);
console.log("id", id);

//using different names for the properties
const { name: personName } = obj;
console.log("personName", personName);
 Run code snippet
Comment

JavaScript Const

const PI = 3.141592653589793;
PI = 3.14;      // This will give an error
PI = PI + 10;   // This will also give an error
Comment

what is const in javascript

const age; // errror as const cannot be kept un-initialized;
const age = 20 ; 
const age = 21 , // error as once declared const variable cann't be
// re-declared in same scope or different scope. 
Comment

JavaScript Constants

const x = 5;
x = 10;  // Error! constant cannot be changed.
console.log(x)
Comment

const in javascript

const value = 10;
const constant = value;
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery change label content 
Javascript :: map function in js 
Javascript :: javascript object methods 
Javascript :: lodash isNil 
Javascript :: Nuxt.js + Electron 
Javascript :: how to check if an element is in array javascript 
Javascript :: reisze image expo react native 
Javascript :: nodejs redis 
Javascript :: validator.js 
Javascript :: npm fund 
Javascript :: vue js documentation 
Javascript :: Check Object Is Instance Of Class 
Javascript :: javascript frames 
Javascript :: javascript image preview before upload 
Javascript :: classes in javascript mdn 
Javascript :: open bootstrap modal using vanilla js 
Javascript :: using server passed values and client js together in ejs 
Javascript :: arrow function in es6 
Javascript :: discordjs 
Javascript :: splice in javascript 
Javascript :: jsonArray find 
Javascript :: Updating a nested object in a document using mongoose 
Javascript :: datatable hide no data available in table 
Javascript :: keyframe options 
Javascript :: How To Use Multiple Styles in REACT 
Javascript :: interval manage for javascript 
Javascript :: split javascript 
Javascript :: react image preview npm 
Javascript :: exports in node js 
Javascript :: debounce reactjs 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =