Is it possible to add a two dot in a variable name in Javascript?

25
April 22, 2019, at 03:20 AM

i want to create a variable like this in javascript

variable1.varible2.variable3 = "Hi Its working";
alert(variable1.varible2.variable3);
Answer 1

You cannot have . in variable names.

You can call a variable pretty much anything you like, but there are limitations. Generally, you should stick to just using Latin characters (0-9, a-z, A-Z) and the underscore character.

If you really want the variable1.varible2.variable3 to return value "Hi Its working". You can use objects.

let variable1 = { 
  variable2:{ 
    variable3:"Soemthing" 
  } 
} 
console.log(variable1.variable2.variable3)

Answer 2

you cant use . for the name of a variable but you can do this with objects:

let person = {
  name: {
    first: 'john',
    last: 'snow'
  },
  eyes: {
    color: 'black'
  }
}
console.log(person.name.first); //john
Answer 3
var car = new Object();
car.type = "Fiat";
car.model = "500";
car.color = "white";
car.engine = {type:"V8", fuel:"diesel"}
console.log(car)
window.alert(car.engine.type) 

Then you could write Car.engine.type = "V8 Turbo"

READ ALSO
Load images by mouseclick

Load images by mouseclick

I am trying do load apng file with p5

20
expo background push notfication in iOS

expo background push notfication in iOS

At first, I was worried that expo had a custom notification system (had me thinking "coulda had a p8", if you know the commercial like that, haha)In the end, I was impressed with how direct and easy sending messages with expo's push notification service...

28
Post back on checkbox change

Post back on checkbox change

I want to post back whenever checkbox is changed for a Tree view, I searched and found answers but it isn't workingWhen i debug it never gets to the event function

50
Saving nested objects(arrays) with mongoose, result empty objects at mongodb

Saving nested objects(arrays) with mongoose, result empty objects at mongodb

The problem is so basic: I want to save nested objects with mongoose in mongodb, but when I save them, nested objects are empty

60