Question:- What is the use of history object?
Answer:- The history object of a browser can be used to switch to history pages such as back and forward from the current page or another page. There are three methods of history object. 1.history.back() - It loads the previous page. 2.history.forward() - It loads the next page. 3.history.go(number) - The number may be positive for forward, negative for backward. It loads the given page number.
Question:- How to write a comment in JavaScript?
Answer:- There are two types of comments in JavaScript. 1. Single Line Comment: It is represented by // (double forward slash) 2. Multi-Line Comment: Slash represents it with asterisk symbol as /* write comment here */
Question:- How to create a function in JavaScript?
Answer:- To create a function in JavaScript, follow the following syntax. function function_name(){ //function body }
Question:- What are the different data types present in JavaScript?
Answer:- There are two types of data types in JavaScript: 1. Primitive data types 2. Non- Primitive data types
Question:- What are the Primitive data types?
Answer:- The primitive data types are as follows: 1. String: The string data type represents a sequence of characters. It is written within quotes and can be represented using a single or a double quote. 2. Number: The number data type is used to represent numeric values and can be written with or without decimals. 3. Boolean: The Boolean data type is used to represent a Boolean value, either false or true. This data type is generally used for conditional testing. 4. BigInt: The BigInt data type is used to store numbers beyond the Number data type limitation. This data type can store large integers and is represented by adding "n" to an integer literal. 5. Undefined: The Undefined data type is used when a variable is declared but not assigned. The value of this data type is undefined, and its type is also undefined. 6. Null: The Null data type is used to represent a non-existent, null, or a invalid value i.e. no value at all. 7. Symbol: Symbol is a new data type introduced in the ES6 version of JavaScript. It is used to store an anonymous and unique value. 8. typeof: The typeof operator is used to determine what type of data a variable or operand contains. It can be used with or without parentheses (typeof(x) or typeof x). This is mainly used in situations when you need to process the values of different types.
Question:- What are Non-Primitive data types?
Answer:- To store multiple and complex values, we have to use non-primitive data types. The non-primitive data types are as follows: 1. Object: The Object is a non-primitive data type. It is used to store collections of data. An object contains properties, defined as a key-value pair. A property key (name) is always a string, but the value can be any data type, such as strings, numbers, Booleans, or complex data types like arrays, functions, and other objects. 2. Array: The Array data type is used to represent a group of similar values. Every value in an array has a numeric position, called its index, and it may contain data of any data type-numbers, strings, Booleans, functions, objects, and even other arrays. The array index starts from 0 so that the first array element is arr[0], not arr[1].
Question:- What is the difference between == and ===?
Answer:- The == operator checks equality only whereas === checks equality, and data type, i.e., a value must be of the same type.
Question:- How to create objects in JavaScript?
Answer:- There are 3 ways to create an object in JavaScript. 1. By object literal 2. By creating an instance of Object 3. By Object Constructor Lets see a simple code to create an object using object literal. emp={id:102,name:"Rahul Kumar",salary:50000}
Question:- What does the isNaN() function?
Answer:- The isNan() function returns true if the variable value is not a number.
Question:- What is the output of "10"+20+30 in JavaScript?
Answer:- 102030 because after a string all the + will be treated as string concatenation operator (not binary +).
Question:- Difference between Client side JavaScript and Server side JavaScript?
Answer:- 1. Client-side JavaScript comprises the basic language and predefined objects which are relevant to running JavaScript in a browser. The client-side JavaScript is embedded directly by in the HTML pages. The browser interprets this script at runtime. 2. Server-side JavaScript also resembles client-side JavaScript. It has a relevant JavaScript which is to run in a server. The server-side JavaScript are deployed only after compilation.
Question:- In which location cookies are stored on the hard disk?
Answer:- The storage of cookies on the hard disk depends on the OS and the browser. The Netscape Navigator on Windows uses a cookies.txt file that contains all the cookies. The path is c:Program FilesNetscapeUsersusernamecookies.txt The Internet Explorer stores the cookies on a file username@website.txt. The path is: c:WindowsCookiesusername@Website.txt.
Question:- In which location cookies are stored on the hard disk?
Answer:- The storage of cookies on the hard disk depends on the OS and the browser. The Netscape Navigator on Windows uses a cookies.txt file that contains all the cookies. The path is c:Program FilesNetscapeUsersusernamecookies.txt The Internet Explorer stores the cookies on a file username@website.txt. The path is: c:WindowsCookiesusername@Website.txt.
Question:- Whats the difference between event.preventDefault() and event.stopPropagation() methods in JavaScript?
Answer:- In JavaScript, the event.preventDefault() method is used to prevent the default behavior of an element. For example: If you use it in a form element, it prevents it from submitting. If used in an anchor element, it prevents it from navigating. If used in a contextmenu, it prevents it from showing or displaying. On the other hand, the event.stopPropagation() method is used to stop the propagation of an event or stop the event from occurring in the bubbling or capturing phase.
