The parseInt() function is used to convert numbers between different bases. It takes the string to be converted as its first parameter, and the second parameter is the base of the given string.
For example-
parseInt("4F", 16)
Posted Date:- 2021-08-23 00:46:30
1. Array slice() method removes the array items from the array and reforms the removed items into a new array. The selected items through an array slice() method are removed from the array and formed as another new array.
2. array splice() method removes the items of the selected array from the array and does not form another array.
Posted Date:- 2021-08-23 00:45:20
The callback is a typical function of JavaScript that can be passed as an option or argument of JavaScript. Sometimes, callbacks can also be termed as simple events. Users are given calls to react to different kinds of triggered situations.
Posted Date:- 2021-08-23 00:43:27
!DOCTYPE html>
<html>
<body>
<h2> <strong> Sample: Software Testing Help</strong> </h2>
<p style='text-decoration:underline'>Example Function Declaration</p>
<p id="display_add"></p>
<p id="display_sub"></p>
<script>
function add(first_num,second_num){
return first_num + second_num;
}
var substract = function sub(first_num,second_num){
return first_num - second_num;
}
var first_num=700;
var second_num=300;
document.getElementById("display_add").innerHTML = "Sum of the number is:" + add(first_num,second_num);
document.getElementById("display_sub").innerHTML = "Difference of the number is:" + substract(first_num,second_num);
</script>
</body>
</html>
As shown in the example add() is a function declaration and subtract() is a function expression. The syntax of the function declaration is like a function which is saved into a variable.
Function declarations are hoisted but function expressions are not hoisted.
Posted Date:- 2021-08-23 00:41:34
One of the differences between the two is that Primitive Data Types are passed By Value and Objects are passed By Reference.
Posted Date:- 2021-08-23 00:37:08
NaN is a short form of Not a Number. Since NaN always compares unequal to any number, including NaN, it is usually used to indicate an error condition for a function that should return a valid number. When a string or something else is being converted into a number and that cannot be done, then we get to see NaN.
In case you are facing any challenges with these JavaScript Interview Questions, please comment on your problems in the section below.
Posted Date:- 2021-08-23 00:34:41
The following DOM Methods are used to capture the HTML element and manipulate it.
01. getElementById('idname') - > This function is used to select the HTML element based on ID
example:-
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<label id="myelement"></label>
<script>
document.getElementById('myelement').innerHTML = '<h3> Welcome </h3>'
</script>
</body
</html>
02. getElementsByClassName('className') - > This function is used to select the HTML elements based on the class name in DOM, it will return all matched HTML element with respect to the class name.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<style>
.lblMsg {
color: #000;
}
</style>
<body>
<label id="myelement" class="lblMsg"></label>
<script>
document.getElementsByClassName('lblMsg')[0].innerHTML = '<h3> Welcome </h3>'
</script>
</body>
</html>
03. getElementsByTagName(‘HTMLtagname’)
> This function is used to select the HTML elements based on the Tag name in DOM, it will return all matched HTML element with respect to the Tag name.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<style>
.lblMsg {
color: #000;
}
</style>
<body>
<label id="myelement" class="lblMsg"></label>
<script>
document.getElementsByTagName('label')[0].innerHTML = '<h3> Welcome </h3>'
</script>
</body>
</html>
Posted Date:- 2021-08-23 00:29:32
BOM (Browser Object Model) which provides interaction with the browser, the default object of the browser is a window. Various property provided by windows is a document, history, screen, location, navigator.
Posted Date:- 2021-08-23 00:28:16
The main difference between “==” and “===” operator is that formerly compares variable by making type correction e.g. if you compare a number with a string with numeric literal, == allows that, but === doesn’t allow that, because it not only checks the value but also type of two variable, if two variables are not of the same type “===” return false, while “==” return true.
Posted Date:- 2021-08-23 00:26:18
Automatic type conversion is supported by javascript and usually, the developers of javascript use the automatic type conversion method.
Posted Date:- 2021-08-23 00:25:26
We can use the window object location to redirect the user to the new page
window.location.href="https://www.dotnettricks.com/"
Posted Date:- 2021-08-23 00:24:08
The three different ways:
Inline
External
Interna
The JavaScript function known as the inline function is assigned to a variable that is created at runtime. On the other hand, if you require a JavaScript for function, you can integrate the script on the page on which you are working or you can place it as a separate file which can be called, when needed. This essentially, becomes the difference between external and internal script.
Posted Date:- 2021-08-23 00:22:25
You can read a cookie as simply as creating a cookie in JavaScript as it is actually the value of the document.cookie object. If you want to access that specific cookie, you can use this string any time.
1. By using the document.cookie string, you can keep a list of name – value pairs which are separated by semicolons, where the name is actually the name of a cookie and the value is the string value.
2. You can also make use of strings’ split() function to break the string into values and keys.
Posted Date:- 2021-08-23 00:20:10
You can create a cookie in JavaScript simply by assigning a string value to the document.cookie object.
The syntax:
document.cookie = “key1 = value1; key2 = value2; expires = date”;
Posted Date:- 2021-08-23 00:19:18
The typeof operator can be used to get the datatype of its operand. The specified operand can be a data structure or a literal such as a function, object or a variable.
Posted Date:- 2021-08-23 00:18:30
A few rules are:
1. One should not use any JavaScript reserved keyword as the variable name.
2. Variable names in JavaScript cannot start with a numerical that is within 0-9.
3. Variable names in JavaScript are case sensitive.
Posted Date:- 2021-08-23 00:17:44
Closure is developed when a specific variable is defined outside the current scope and it is accessed from within with some inner scope.
Posted Date:- 2021-08-23 00:16:36
In JavaScript, we can submit a form by using
document.form[0].submit();
Posted Date:- 2021-08-23 00:15:51
“This” keyword is an object in a javascript, where it refers to. It has different values at different stages, whereas in method “this” is used as an owner object and in function, it is called a global object.
Posted Date:- 2021-08-23 00:15:14
There are two types of functions that are supported by JavaScript. They are -
Anonymous function- This type of function generally has no name and this is the difference between it and a normal function.
Named function- On the other hand, this function is named properly and specifically.
Posted Date:- 2021-08-23 00:14:24
Two ways are available to read and write a file, they are:
1. JavaScript Expressions
2. Webpages and Active X objects
Posted Date:- 2021-08-23 00:13:14
The three possible ways of defining a variable in JavaScript are:
Var – The JavaScript variables statement is used to declare a variable and, optionally, we can initialize the value of that variable. Example: var a =10; Variable declarations are processed before the execution of the code.
Const – The idea of const functions is not allow them to modify the object on which they are called. When a function is declared as const, it can be called on any type of object.
Let – It is a signal that the variable may be reassigned, such as a counter in a loop, or a value swap in an algorithm. It also signals that the variable will be used only in the block it’s defined in.
Posted Date:- 2021-08-23 00:09:21
Attributes- provide more details on an element like id, type, value etc.
Property- is the value assigned to the property like type=”text”, value=’Name’ etc.
Posted Date:- 2021-08-23 00:08:12
How to delete a cookie using JavaScript?
If you want to delete a cookie so that subsequent attempts to read the cookie in JavaScript return nothing, you just need to set the expiration date to a time in the past. You should define the cookie path to ensure that you delete the right cookie. Some browsers will not let you delete a cookie if you don’t specify the path.
Posted Date:- 2021-08-23 00:07:30
They are also known as ‘Immediately Invoked Function Expressions’ or ‘Self Executing Anonymous Functions’. These functions are invoked automatically in the code, hence they are named as ‘Self Invoking Functions’.
Usually, we define a function and invoke it, but if we want to execute a function automatically where it is explained, and if we are not going to call it again, we can use anonymous functions. And these types of functions have no name.
Posted Date:- 2021-08-23 00:04:32
The simplest way to create a cookie is to assign a string value to the document.cookie object, which looks like this-
Syntax :
document.cookie = "key1 = value1; key2 = value2; expires = date";
Posted Date:- 2021-08-23 00:03:21
Yes, We can break JavaScript code into several lines; we can break within a string statement using a backslash (‘’) at the end of the first line code.
For example, document.write (“This is a program”);
And when you are not within a strong statement and want to change to a new line, then JavaScript ignores the break in the line.
For Example: var x=1, y=2,
z=x+y;
The above code is perfect for better understanding, but it might hamper our debugging, so it is not advisable to write.
Posted Date:- 2021-08-23 00:02:24
Negative Infinity is nothing but a number in JavaScript that can be derived by dividing negative numbers by zero. This could be generated by arithmetic operations.
Posted Date:- 2021-08-23 00:00:30
Obviously, JavaScript is faster.
JavaScript is more rapid because, as JS is a client-side language and that it does not need any assistance or help of the webserver to execute, but on the other hand, ASP is a server-side language. That’s why ASP is always slower than JavaScript.
JS now is also known as a server-side language named NodeJS.
Posted Date:- 2021-08-22 23:59:51
The following rules are to be followed while naming variables in JavaScript:
1. You should not use any of the JavaScript reserved keyword as variable name. For example, break or boolean variable names are not valid.
2. JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or the underscore character. For example, 123name is an invalid variable name but _123name or name123 is a valid one.
3. JavaScript variable names are case sensitive. For example, Test and test are two different variables.
Posted Date:- 2021-08-22 23:58:53
NaN property represents “Not-a-Number” value. It indicates a value which is not a legal number.
typeof of a NaN will return a Number .
To check if a value is NaN, we use the isNaN() function,
Posted Date:- 2021-08-22 23:57:04
JavaScript is a dynamically typed language. In a dynamically typed language, the type of a variable is checked during run-time in contrast to statically typed language, where the type of a variable is checked during compile-time.Since javascript is a loosely(dynamically) typed language, variables in JS are not associated with any type. A variable can hold the value of any data type.
For example, a variable which is assigned a number type can be converted to a string type:
var a = 23;
var a = "Hello World!";
Posted Date:- 2021-08-22 23:55:32
The JavaScript this keyword refers to the object it belongs to. This has different values depending on where it is used. In a method, this refers to the owner object and in a function, this refers to the global object.
Posted Date:- 2021-08-22 23:53:54
The scope of a variable is the region of your program in which it is defined. JavaScript variable will have only two scopes.
Global Variables − A global variable has global scope which means it is visible everywhere in your JavaScript code.
Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.
Posted Date:- 2021-08-22 22:35:00
Yes! An anonymous function can be assigned to a variable. It can also be passed as an argument to another function.
In case you are facing any challenges with these JavaScript Interview Questions, please comment on your problems in the section below.
Posted Date:- 2021-08-22 22:33:24
Obviously, JavaScript is faster.
JavaScript is more rapid because, as JS is a client-side language and that it does not need any assistance or help of the webserver to execute, but on the other hand, ASP is a server-side language. That’s why ASP is always slower than JavaScript.
JS now is also known as a server-side language named NodeJS.
Posted Date:- 2021-08-22 22:32:01
The popups available in JavaScript are Alert, Prompt, and Confirm.
Posted Date:- 2021-08-22 22:31:22
If no value has been given to the variable then, it is called a null object (or) null value.
Posted Date:- 2021-08-22 22:31:00
Given below are the characteristics of ‘Strict Mode’:
‘Strict Mode’ will stop developers from creating global variables.
Developers are restricted from using duplicate parameters.
Strict mode will restrict you from using the JavaScript keyword as a variable name or function name.
Strict mode is declared with ‘use strict’ keyword at the beginning of the script.
All browsers support strict mode.
Posted Date:- 2021-08-22 22:30:27
‘Strict mode’ is a restricted variant of JavaScript. Usually, this language is ‘not very strict’ in throwing errors. But in ‘Strict mode’ it will throw all types of errors, even the silent errors. Thus, the process of debugging becomes easier. And the chances for making a mistake for the developer is reduced.
Posted Date:- 2021-08-22 22:29:53
JavaScript is one of the three languages all web developers must learn:
(1). HTML is used to define the content of web pages. It is otherwise known as the skeleton of web pages.
(2). CSS is used to specify the layout or give styling to the web pages, otherwise known as the shape of the body or cover of the skeleton.
(3). JavaScript to program the behaviour of web pages or web pages workability.
Posted Date:- 2021-08-22 22:29:13
JavaScript was launched in year September 1995.
JavaScript was created by a Netscape programmer, Brendan Eich.
He developed this new scripting language in just ten days.
At the time of launch, it was initially named Mocha, after which it was known as Live Script and later known as JavaScript.
Posted Date:- 2021-08-22 22:28:47
Netscape company had developed the JavaScript Programming Language.
Posted Date:- 2021-08-22 22:23:06
Even though global variables are easy to use, these have some shortfalls. While using this type of variable, the problem of clashing the variable names of different global and local scope occurs. The code that is often relied on the global variable also gets difficult to be tested and debugged.
Posted Date:- 2021-08-22 22:21:52
A global variable is a special kind of variable in JavaScript. This variable is easy to use and also available across the entire length of the JavaScript code. Mainly, the var keyword is used whether to declare a global or local variable.
Posted Date:- 2021-08-22 22:21:05
JavaScript data are of the following types -
1.String
2.Function
3.Boolean
4.Object
5.Number
6.Null
Posted Date:- 2021-08-22 22:20:34
This Scripting language has many advantages as stated below.
Lightweight: It is easy to implement. It has small memory footprints.
Interpreted: It is an interpreted language. Instructions are executed directly.
Object-oriented: It is an object-oriented language.
First-class functions: In JavaScript, a function can be used as a value.
Scripting Language: It’s a language in which instructions are written for a run-time environment.
Posted Date:- 2021-08-22 22:19:14
Both test () and exec () are RegExp expression methods.
By using a test (), we will search a string for a given pattern, if it finds the matching text then it returns the Boolean value ‘true’ or else it returns ‘false’.
But in exec (), we will search a string for a given pattern, if it finds the matching text then it returns the pattern itself or else it returns ‘null’ value.
Posted Date:- 2021-08-22 22:18:43
JavaScript was launched in year September 1995.
JavaScript was created by a Netscape programmer, Brendan Eich.
He developed this new scripting language in just ten days.
At the time of launch, it was initially named Mocha, after which it was known as Live Script and later known as JavaScript.
Posted Date:- 2021-08-22 22:18:05
JavaScript is a client-side scripting language as well as a server-side scripting language. This scripting language can be written into HTML pages (also could use CSS for styling the pages), and web browsers understand the page.
This scripting language also acts like an object-oriented programming language but not a class-based object-oriented language.
Posted Date:- 2021-08-22 22:17:45