JavaScript Questions
JavaScript Questions
Cross-platform
Java creates applications that JavaScript code can run only in the
can run in any virtual machine browser, but it can now run on the
(JVM) or browser. server via Node.js.
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.
Example:
Number: The number data type is used to represent numeric values and can be written
with or without decimals.
Example:
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.
Example:
1. var x = 5;
2. var y = 6;
3. var z = 5;
4. (x == y) // returns false
5. (x == z) //returns true
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.
Example:
1. var bigInteger = 123456789012345678901234567890;
2. // This is an example of bigInteger.
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.
Example:
Null: The Null data type is used to represent a non-existent, null, or a invalid value i.e.
no value at all.
Example:
1. var x = null;
Symbol: Symbol is a new data type introduced in the ES6 version of JavaScript. It is used
to store an anonymous and unique value.
Example:
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.
Example:
In the above examples, we can see that the primitive data types can store only a single
value. To store multiple and complex values, we have to use non-primitive data types.
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.
Example:
1. // Collection of data in key-value pairs
2. var obj1 = {
3. x: 123,
4. y: "Welcome to JavaTpoint",
5. z: function(){
6. return this.x;
7. }
8. }
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].
Example:
What is BOM?
BOM stands for Browser Object Model. It provides interaction with the
browser. The default object of a browser is a window. So, you can call
all the functions of the window by specifying the window or directly.
The window object provides various properties like document, history,
screen, navigator, location, innerHeight, innerWidth.
What is DOM? What is the use of document
object?
DOM stands for Document Object Model. A document object
represents the HTML document. It can be used to access and change
the content of HTML.