Answer & Solution
<script> element and is accessible within the script, printing 'Hello' when using console.log.
element and is accessible within the script, printing 'Hello' when using console.log.",
"answerCount": 4,
"dateCreated": "2024-05-24",
"author": {
"@type": "Organization",
"name": "MYTAT"
},
"suggestedAnswer": [
{
"@type": "Answer",
"text": "Hello"
},
{
"@type": "Answer",
"text": "Undefined"
},
{
"@type": "Answer",
"text": "Error"
},
{
"@type": "Answer",
"text": "'Hello'"
}
],
"acceptedAnswer": {
"@type": "Answer",
"text": "Hello",
"dateCreated": "2024-05-24",
"author": {
"@type": "Organization",
"name": "MYTAT"
}
}
}
}
<br> <br> <script> <br>var globalVar = 'Hello'; <br>console.log(globalVar); <br> </script>
<script> element and is accessible within the script, printing 'Hello' when using console.log.
Which HTML element is commonly used to store and access global data attributes in HTML?
A). <form>
B). <body>
C). <head>
D). <html>
Which of the following best describes the relationship between global variables in HTML and CSS?
A). Global variables in HTML can be accessed directly within CSS using custom CSS properties
B). Global variables in HTML must be converted to CSS variables before they can be used in CSS
C). Global variables in HTML and CSS are unrelated and cannot interact with each other
D). Global variables in HTML can only be accessed within the HTML document and cannot be used in CSS
What is a global variable in HTML?
A). A variable declared inside a function
B). A variable declared outside of any function or block
C). A variable declared within an HTML element
D). A variable declared with the global attribute
What is the purpose of using global variables within HTML elements using custom data attributes?
A). To store and retrieve data specific to each HTML element
B). To restrict access to data within specific HTML elements
C). To create variables with limited scope within HTML elements
D). To avoid using JavaScript for data manipulation
How can you ensure that a global variable defined in an external JavaScript file is accessible within an HTML document?
A). By linking the external JavaScript file using the <link> element
B). By using the import statement to import the variable from the external file
C). By using the defer attribute in the <script> tag that links the external file
D). By using the <script> tag to link the external JavaScript file
Which HTML element is commonly used to define global variables in HTML?
A). <div>
B). <variable>
C). <script>
D). <global>
What is the correct syntax for accessing a global data attribute named 'global-var' from an HTML element with the ID 'myElement' using JavaScript?
A). document.querySelector('#myElement').getAttribute('data-global-var');
B). document.getElementById('myElement').getAttribute('global-var');
C). document.getElementById('myElement').getAttribute('data-global-var');
D). document.querySelector('#myElement').getAttribute('global-var');
What is the purpose of using global variables in HTML?
A). To store data temporarily within a specific HTML element
B). To store data that needs to be shared and accessed across different parts of an HTML document
C). To restrict access to variables within a specific HTML element
D). To prevent accidental modification of variables
What is the correct syntax for defining a global variable in HTML using the <script> element?
A). <script globalVar='value'>
B). <script var='globalVar' value='value'>
C). <script global var='globalVar' value='value'> </script>
D). <script global='globalVar' value='value'> </script>
What is the purpose of using the defer attribute in a <script> element in HTML?
A). To delay the loading of the script until after the HTML content is parsed
B). To prevent the script from executing unless triggered manually
C). To execute the script asynchronously
D). To specify the script's global variables