Javascript Note
Javascript Note
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.
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.
• 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?
Primitive
• Numbers
• Strings
• Boolean
Non-primitive
• Objects
• Functions
• Arrays
Trivial
• Null
• Undefined
Cont student{
Name:”shubham”;
Age:24;
SessionState: It's user-specific containing the data of the user session and allows access to
all data on the web pages.
A break statement is a way to exit the current loop. The continue statement continues with
the next statement of the loop.
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.
Attributes- It provides more details on an element like id, type, value, etc.
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.
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.
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.
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.
***************************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.