简体   繁体   中英

How to define test for nested(?) const, JavaScript

I'm using javascript for the first time in a work setting, and have to test a code running within our questionnare solution. The answers can only be true or false, and the check is written like this:

if(Page.Group.Question.Answer){*do something*};

In my test-code I have to define Page.Group.Question.Answer myself and I can't seem to find out how to do it, although I am sure it is quite easy. I have tried the following so far:

var Page.Group.Question.Answer = true;

and

let Page.Group.Question.Answer = true;

And then I tried to define a const, but I couldn't find out how it should be nested.

What is the correct syntax?

With some help from Jaromanda X and deceze the answer is that I need to define it as:

const Page = {Group: {Question: {Answer: true}}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM