Chduzb
Chduzb
Answer:
var: var is function-scoped and can be redeclared. It is hoisted to the top of its scope but may lead to
unexpected behavior due to its global scope or function scope.
let: let is block-scoped and cannot be redeclared within the same scope. It is also hoisted but not
initialized until execution.
const: const is also block-scoped and is used to declare constants. Variables declared const cannot be
reassigned. However, if the constant is an object or array, its properties or elements can still be
modified.
What is the DOM and how does JavaScript interact with it?
Answer: The DOM (Document Object Model) is a programming interface for HTML and XML documents.
It represents the structure of a document as a tree of nodes, where each node corresponds to an
element, attribute, or piece of text. JavaScript can manipulate the DOM to dynamically update the
content, style, and structure of a webpage by adding, removing, or modifying nodes.
Answer: JavaScript modules are reusable pieces of code that can be exported from one file and
imported into another. This promotes code organization and reuse. ES6 introduced native support for
modules in JavaScript.
Primitive Types: string, number, boolean, null, undefined, symbol, and bigint.
Object Types: Objects, arrays, and functions are considered complex data types in JavaScript.
Answer: JavaScript is a high-level, interpreted programming language that enables interactive web
pages. It is used to manipulate the Document Object Model handle events, perform asynchronous
operations, and create dynamic content. JavaScript runs on the client side (in the browser) but can also
be used on the server side with environments like Node.js.
HTML stands for HyperText Markup Language. It’s a standard markup language used to create web
pages.
What is the basic structure of an HTML document?
An HTML document typically starts with <!DOCTYPE html> and contains <html>, <head>, and <body>
tags.
HTML elements are the building blocks of web pages, and tags are used to define and format elements.
For example, <p> defines a paragraph.
<div> is a block-level element used for grouping content, while <span> is an inline-level element used to
apply styles to a portion of text.
What does CSS stand for, and why is it important in web development?
CSS stands for Cascading Style Sheets. It’s crucial for controlling the presentation and layout of web
pages, making them visually appealing.
You can link an external CSS file using the <link> element in the HTML document’s <head> section.
Padding is the space inside an element, while margin is the space outside of it. Padding affects the
content area, while the margin affects the element’s positioning in the layout.
You can declare a variable using var, let, or const. For example, let myVar = 5.
Null represents an intentional absence of any object value, while undefined signifies a variable that has
been declared but hasn’t been assigned a value.
A function is a reusable block of code. You can define one using the function keyword, for example,
function myFunction() { … }.
C) /* Comment */
D) Both B and C
JavaScript data types are categorized into two parts i.e. primitive and non-primitive types.
Primitive Data Type: The predefined data types provided by JavaScript language are known as primitive
data type. Primitive data types are also known as in-built data types.
Numbers
Strings
Boolean
Symbol
Undefined
Null
BigInt
Non-Premitive Data Type: The data types that are derived from primitive data types are known as non-
primitive data types. It is also known as derived data types or reference data types.
Objects
Functions
Arrays
Comments prevent the execution of statements. Comments are ignored while the compiler executes the
code. There are two type of symbols to represent comments in JavaScript:
/*
Multi-line comments
...
*/
Here, 3 and 2 behave like an integer, and “7” behaves like a string. So 3 plus 2 will be 5. Then the output
will be 5+”7″ = 57.
The number isNan function determines whether the passed value is NaN (Not a number) and is of the
type “Number”. In JavaScript, the value NaN is considered a type of number. It returns true if the
argument is not a number, else it returns false.
Yes, it is possible to break the JavaScript code into several lines in a string statement. It can be broken by
using the ‘\n’ (backslash n).
Undefined: It occurs when a variable is declare but not assign any value. Undefined is not a keyword.
Undeclared: It occurs when we try to access any variable which is not initialize or declare earlier using
the var or const keyword. If we use ‘typeof’ operator to get the value of an undeclare variable, we will
face the runtime error with the return value as “undefined”. The scope of the undeclare variables is
always global.
What are global variables? How are these variables declared, and what are the problems associated with
them?
In contrast, global variables are the variables that define outside of functions. These variables have a
global scope, so they can be used by any function without passing them to the function as parameters.
What do you mean by NULL in JavaScript?
The NULL value represents that no value or no object. It is known as empty value/object.
The prompt box is a dialog box with an optional message prompting the user to input some text. It is
often used if the user wants to input a value before entering a page. It returns a string containing the
text entered by the user, or null
while loop: A while loop is a control flow statement that allows code to be executed repeatedly based
on a given Boolean condition. The while loop can be thought of as a repeating if statement.
for loop: A for loop provides a concise way of writing the loop structure. Unlike a while loop, for
statement consumes the initialization, condition and increment/decrement in one line thereby providing
a shorter, easy to debug structure of looping.
do while: A do-while loop is similar to while loop with the only difference that it checks the condition
after executing the statements, and therefore is an example of Exit Control Loop.
In JavaScript, parseInt() function is used to convert the string to an integer. This function returns an
integer of base which is specified in second argument of parseInt() function. The parseInt() function
returns Nan (not a number) when the string doesn’t contain number.
Alert
Confirm
Prompt
Write the errors shown in JavaScript?
Syntax error: A syntax error is an error in the syntax of a sequence of characters or tokens that are
intended to be written in a particular programming language.
Logical error: It is the most difficult error to be traced as it is the error on the logical part of the coding or
logical error is a bug in a program that causes to operate incorrectly and terminate abnormally.
Runtime Error: A runtime error is an error that occurs during the running of the program, also known as
an exception.
There are four possible ways to access HTML elements in JavaScript which are:
getElementsByClass() Method: It is used to get all the elements that have the given classname.
getElementsByTagName() Method: It is used to get all the elements that have the given tag name.
querySelector() Method: This function takes CSS style selector and returns the first selected element.