in Education by
If there are more than one file(main.lua) which contains code and I declare some variables and functions global. Are these variables and functions global in all files or can I access them through any file? And also is there any problem if I use only global variables and functions? I am using director class JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Globals are not bad by definition, but in general you should only use them when you really need to share data. Otherwise you will end up with pieces of code which should not interact, but do share a variable in an unexpected way ( think temporary variables etc etc). The best approach is to declare everything local unless you absolutely must share the variable.

Related questions

+1 vote
    What is the default value of local and global variables in C Programming?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    Which component do you need to use in order to read data line by line from an input flow ... entries into iterative global variables? tIterateToFlow tFileList tFlowToIterate tLoop...
asked Mar 24, 2021 in Technology by JackTerrance
0 votes
    This smells buggy, but probably, someone can explain it: The following script doesn't work, the output is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    When a function is defined then the system stores parameters and local variables in an area of memory. What this memory is known as?...
asked Nov 26, 2020 in Technology by JackTerrance
0 votes
    In which process, a local variable has the same name as one of the instance variables? a) Serialization ... stackoverflow.com 🔗Source: Java Interview Questions and Answers...
asked Dec 19, 2020 in Technology by Editorial Staff
0 votes
    What are the differences between local and global temporary tables?...
asked Nov 9, 2020 in Technology by Editorial Staff
0 votes
    How to access global and context variables in Talend?...
asked May 30, 2021 in Technology by JackTerrance
0 votes
    What is the difference between global and static global variables?...
asked Jan 23, 2021 in Technology by JackTerrance
0 votes
    So I've got some C code: #include #include /* putting one of the "char*"s here causes a segfault ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    In a function, How to create and use a global variable? How can I use it in other functions? Is it compulsory ... it in a function? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I want to set some global variables inside a function, how can I do that? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I am fairly new to Java, I wanted to know how can i define a global variable ? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Which of the following global variables is used to get parameters? (a) HTTP_GET_VAR[] (b) HTTP_GET_VARS() ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    Which global variables can be used to determine if a transaction is still open? (a) @@NESTLEVEL (b) ... Results topic in portion Query Processing Techniques of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    Which of the following are global functions that are not part of core JavaScript? (a) spawn(f); ( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
...