0% found this document useful (0 votes)
5 views6 pages

Chduzb

The document explains key concepts in JavaScript, HTML, and CSS, including variable declarations (var, let, const), the Document Object Model (DOM), and JavaScript modules. It also covers data types, commenting methods, and the structure of HTML documents, as well as CSS's role in web development. Additionally, it discusses error types in JavaScript and methods to access HTML elements programmatically.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Chduzb

The document explains key concepts in JavaScript, HTML, and CSS, including variable declarations (var, let, const), the Document Object Model (DOM), and JavaScript modules. It also covers data types, commenting methods, and the structure of HTML documents, as well as CSS's role in web development. Additionally, it discusses error types in JavaScript and methods to access HTML elements programmatically.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Explain the difference between var, let, and const.

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.

What are JavaScript modules and how do you use them?

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.

What are JavaScript data types?

Answer: JavaScript data types include:

Primitive Types: string, number, boolean, null, undefined, symbol, and bigint.

Object Types: Objects, arrays, and functions are considered complex data types in JavaScript.

What is JavaScript and how is it used in web development?

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.

What is HTML, and what does it stand for?

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.

What are HTML elements and 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.

Explain the difference between <div> and <span> elements.

<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.

How do you link an external CSS file to an HTML document?

You can link an external CSS file using the <link> element in the HTML document’s <head> section.

Explain the difference between padding and margin in CSS.

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.

How do you declare a variable in JavaScript?

You can declare a variable using var, let, or const. For example, let myVar = 5.

Explain the difference between null and undefined in JavaScript.

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.

What is a function in JavaScript, and how do you define one?

A function is a reusable block of code. You can define one using the function keyword, for example,
function myFunction() { … }.

How can you add a comment in a JavaScript file?

A) <!– Comment –>


B) // Comment

C) /* Comment */

D) Both B and C

What are Data Types in JavaScript?

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

Which symbol is used for comments in JavaScript?

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:

Double slash: It is known as a single-line comment.

// Single line comment


Slash with Asterisk: It is known as a multi-line comment.

/*

Multi-line comments

...

*/

What would be the result of 3+2+”7″?

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.

What is the use of the isNaN function?

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.

Is it possible to break JavaScript Code into several lines?

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).

What are undeclared and undefined variables?

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.

What is a prompt box?

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

What are all the looping structures in JavaScript?

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.

How to convert the string of any base to integer in JavaScript?

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.

What are the types of Pop up boxes available in JavaScript?

There are three types of pop boxes available in JavaScript.

Alert

Confirm

Prompt
Write the errors shown in JavaScript?

There are three different types of errors 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.

How many ways an HTML element can be accessed in JavaScript code?

There are four possible ways to access HTML elements in JavaScript which are:

getElementById() Method: It is used to get the element by its id name.

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.

You might also like