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 :: Apollo graphql fragment 
Javascript :: string.length 
Javascript :: redux thunk 
Javascript :: javascript iterable 
Javascript :: image file upload in angular 
Javascript :: leaflet geojson style stroke width 
Javascript :: phaser generate frame numbers 
Javascript :: configure angular router apache 
Javascript :: emergency food 
Javascript :: json schema e.g. 
Javascript :: clear input fild 
Javascript :: full form of json 
Javascript :: sitecore rendering paramaters get 
Javascript :: disable eslint curly option 
Javascript :: obfuscate js code 
Javascript :: jquery get table 
Javascript :: will console.log will be automatically disabled in react native for development build 
Javascript :: console.log full object 
Javascript :: react native test redux 
Javascript :: what is the use of useparams in react 
Javascript :: date difference without weekends using moment js 
Javascript :: scroll div horizontally with move wheel js 
Javascript :: vue 3 $refs 
Javascript :: hide an element when window resize css 
Javascript :: hook usePreloadImages 
Javascript :: react useState update object in array of objects 
Javascript :: what is angularjs 
Javascript :: await vuex dispatch true 
Javascript :: #{} js 
Javascript :: react get current date minus 7 days 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =