0% found this document useful (0 votes)
31 views

Javascript Note

Uploaded by

shubham001.v
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Javascript Note

Uploaded by

shubham001.v
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.What is JavaScript?

JavaScript is a object-oriented scripting language. It allows you to build interactivity into


static HTML pages.
* Netscape, Internet Explorer, and other web browsers include the language's general-
purpose core.

2.What are the benefits of JavaScript over other web-based technologies?

Interactive Enhancement:JavaScript interacts with static web pages and makes them
respond to users' inputs.

Quick Feedback:

There is no reason for a page on the internet to load again when using JavaScript. For
example, form input validation.

Rich User Interface:

JavaScript assists in making the user interface of web-based applications look and feel
better.

Frameworks:

JavaScript has vast libraries and frameworks that can be widely used to develop games and
web-based applications.

3.What are the features of JavaScript?

These are some of the features of JavaScript:

• Cross-platform compatible
• Open-source
• Object-oriented
• Integration with various front-end and back-end technologies
6.What are the different data types present in JavaScript?

There are three major data types present in JavaScript.

Primitive

• Numbers
• Strings
• Boolean
Non-primitive

• Objects
• Functions
• Arrays

Trivial

• Null
• Undefined

10.What are the main differences between Java and JavaScript?


Java is a general-purpose programming language that is class-based, whereas JavaScript is
an interpreted scripting language. Java is used to create complete applications that may run
on a single computer or be distributed among servers and clients in a network. JavaScript is
used to create interactive webpages that may respond to user actions.

11.Which company developed JavaScript?


The language was developed by Brenden Eich in 1995 when he was working as an
employee of netscape. He is also the founder of Mozilla foundation.

12.What are classes in Javascript?


Classes in Javascript are templates for building objects. Classes bind the data with code so that the
data works as per the code.

14.How can you create objects in JavaScript?

Because JavaScript is fundamentally an object-oriented scripting language, it encourages


and supports using objects when developing web-based applications.

Cont student{

Name:”shubham”;

Age:24;

20.What are the rules for naming a variable in JavaScript?


• Variable names should not be identical to the reserved keywords. For example,
var, let, const, etc.
• Variable names can't start with a numeric value. They should only begin with the
letter or underscore character.
• Variable names have a case-sensitive nature.
28.What does the prompt box mean in JavaScript?
It displays an interactive dialog box that displays an optional prompt for users to enter
some text. It is typically used when users want to enter a number before entering a
webpage.

29.What is NULL in JavaScript?


The NULL value signifies no value or no object. It is also known as an empty value or empty
object.

30.What is the "this" keyword in JavaScript?


"this" refers to an object running the current line of code. It is a reference to the object
which executes the current function.

33.Differentiate between ViewState and SessionState?

ViewState: It is specific to the page state within the browser in a session.

SessionState: It's user-specific containing the data of the user session and allows access to
all data on the web pages.

34.What is the use of the === operator?


The ===(equal to & type) operator is a strict comparison operator, meaning it checks for
both the value and the type of two variables.

37.What is the main difference between "==" and "===" in JavaScript?

40.List all Pop-up box types in JavaScript.


The pop-up boxes available in JavaScript are Alert, Confirm, and Prompt.

42.Differentiate between an alert box and a confirmation box.


An alert box shows only one button, an OK button. A confirmation box has two buttons: the
OK and Cancel buttons.

46.What are break and continue statements?

A break statement is a way to exit the current loop. The continue statement continues with
the next statement of the loop.

48.How to create Generic objects in JavaScript?


Generic objects can be created by:

Var obj=new object();

2.What keywords are used to handle the exceptions?


The keywords commonly used to handle exceptions are: try, catch, finally, throw, and
throws.

3.How to print screen in JavaScript?


By calling the window.print() method in the browser, we can print the content of the
current window in JavaScript

5.What are the looping structures in JavaScript?

while loop: A while loop control flow statement that allows code to run repeatedly in
response to a Boolean condition. The while loop is considered a repeated if statement.

for loop: A for loop offers an easy structure to write. In contrast to a while loop, for
statement combines an initialization process, condition, and increment/decrement in one
line, thereby giving a simpler, easier-to-understand looping structure.

do while: A do-while loop can be like a while loop, but with the exception that it examines
the condition after executing the statements, which is why it's an instance of the Exit
Control Loop.

9.What is the main difference between Attributes and Property?

Attributes- It provides more details on an element like id, type, value, etc.

Property- The value assigned to the property such as type="text" value='Name'.

10.How an HTML element is accessible in JavaScript code?

getElementById('idname'): Gets an element by its ID name.

getElementsByClass('classname'): Gets all the elements that have the given class name.

getElementsByTagName('tagname'): Gets all the elements with the given tag name.

querySelector(): It returns the first selected element using a CSS style selector.

11.In what ways a JavaScript code can be involved in an HTML file?


There are three ways that a JavaScript code can be used in the HTML file: Inline, Internal,
and External.
13.What is a Typed language?

Typed Language is where the datatype is defined which is interpreted by the machine at
runtime.The typed language can be classified into two types:

Dynamically: In this case, the variable could contain multiple types; just like in JS
variables, a variable can be a number or characters.

Statically: In this case, the variable can only hold one data type. Like Java, the variable
declared of string can hold only one set of characters.

What's the difference between a window and a document?

JavaScript window can be described as a global object that contains properties and
methods that interact with it.

The document is a part of the window and is considered as the property of the window.

9.What are Exports and Imports?


Imports and exports allow the writing of modular JavaScript code. With the help of exports
and imports, we can break the code into multiple files.

21.What is the difference between let and var?


The variables that are declared using ‘Let’ are only used within the block where they are declared.
The variables declared by ‘Var’ are available across the function where they are declared.

23.What are the types of errors found in JavaScript?

JavaScript has three types of errors: Runtime, Logical, and Syntax.

Syntax errors- These occur when the code violates the rules of the JavaScript language.
For example, a missing semicolon, an unclosed string, or an unexpected token.

Logical errors - These occur when the code does not produce the desired outcome, but
there is no error message displayed. Logical errors are usually caused by mistake in the
code's logic or algorithm.

Runtime errors- These occur when the code is syntactically correct and logically sound,
but still throws an error during execution. For example, accessing an undefined variable,
calling a function that does not exist, or attempting to divide by zero.

24.Explain how DOM is utilized in JavaScript.


Document Object Model (DOM) is how different objects in a document interact with each
other. It is used for developing web pages that include objects like paragraphs, links, etc.
These Objects can be made to perform actions like add or delete. Also, it adds extra abilities
to a web page.

***************************coding part******************************
2.
How would you create a function that takes two numbers and adds them together?

Function addNumber(num1,num2)
{
Return num1+num2;
}
Let result = addNumber(2,3);
Console.log(result;) //output 5.

4.
How do you create a for loop in JavaScript?

For(i=0;i<5;i++)
{console.log(i)};

8.
How would you go about creating a method that returns the sum of all the elements in an
array?

Let arr=[1,2,3,4];
Let result=arr.reduce((acc,val)=>acc+val,0);
Console.log(result); //output 10.

You might also like