JavaScript Descriptive Part-3

JavaScript Descriptive :

1. What are the difference between alert() and prompt()?
An alert box is often used if you want to make sure information comes through to the user.
When an alert box pops up, the user will have to click "OK" to proceed.
Syntax: alert("sometext");
A prompt box is often used if you want the user to input a value before entering a page.
When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value.
If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null.
Syntax: prompt("sometext","defaultvalue");

2. What is the function of typeof operator in JavaScript?
The "typeof" operator in JavaScript allows us to probe the data type of its operand, such as whether a variable is string, numeric, or even undefined. The below simple example alerts the data type of the variable "myvar"
var myvar=5
alert(typeof myvar) //alerts "number"

3. What do you mean by object? Write 5 built in objects in JavaScript?
An object is a collection of properties or variable and methods. Objects may be user define or built in.
Some built in objects are Math, Date, Window, History, Location, Navigator, Array, String etc.

4. What is the function of floor(), ceil() and round() methods of Math object?
The floor() method rounds a number DOWNWARDS to the nearest integer, and returns the result. Syntax: Math.floor(x)
The ceil() method rounds a number UPWARDS to the nearest integer, and returns the result.Syntax: Math.ceil(x)
The round() method rounds a number to the nearest integer.Syntax: Math.round(x)

5. How to use ternary operator in JavaScript?
The ternary operator will accept three operands and is used to assign a certain value to a variable based on a condition. The syntax is condition ? result1 : result2;
So if the the condition is evalued as true the result1 is runned else result2.

6. What is escape sequence? How to use this?
Escape sequences allow user to parse string literals in JavaScript for special characters/ formatting, such as newlines within a TEXTATEA's input. Below lists these escape sequences:
Example: alert("Welcome to JavaScript \nEnjoy your stay!")

7. What is Regular Expression?
Regular expressions are a powerful tool for performing pattern matches in Strings in JavaScript. We can perform complex tasks that once required lengthy procedures with just a few lines of code using regular expressions. Regular expressions are implemented in JavaScript in two ways:
a.Literal syntax:
//match all 7 digit numbers
var phonenumber= /\d{7}/
b.Dynamically, with the RegExp() constructor:
//match all 7 digit numbers (note how "\d" is defined as "\\d")
var phonenumber=new RegExp("\\d{7}", "g")

8. What are JavaScript Data Types?
JavaScript data types are Number, String, Boolean, Function, Object, Null, Undefined

9. What is the difference between undefined value and null value?
(i) Undefined value cannot be explicitly stated that is there is no keyword called undefined whereas null value has keyword called null
(ii) typeof undefined variable or property returns undefined whereas typeof null value returns object

10. What is eval() in JavaScript?
The eval() method is incredibly powerful allowing us to execute snippets of code during execution in JavaScript.

script type="text/javascript">
var USA_Texas_Austin = "521289";
document.write("Population is "+eval( USA_Texas_Austin));

This produces
Population is 521289

11. What is String Concatenation?
Joining two or more strings is known as string concatenation. In JavaScript we can do this in two ways:
1. + operator. The + operator does string concatenation as soon as one of its operands is a string. Then the other operand is converted to string. Example:
document.write( "Say hello " + 7 + " times fast!");
output=’Say hello 7 times fast!’

2. Joining an array of strings. Collect the strings to be concatenated in an array and join it afterwards.
var arr = new Array();
arr[0]="Say hello ";
arr[1]=7;
arr[2]=" times fast";
document.write( arr.join(" "));

output=’Say hello 7 times fast’


Post a Comment

আপনার কোন কিছু জানার থাকলে কমেন্টস বক্স এ লিখতে পারেন। আমরা যথাযত চেস্টা করব আপনার সঠিক উত্তর দিতে। ভালো লাগলে ধন্যবাদ দিতে ভুলবেন না। শিক্ষার্থীরা নোট ,সাজেশান্স ও নতুন নতুন ভিডিও সবার আগে পেতে আমাদের Web School BD চ্যানেলটি সাবস্ক্রাইব SUBSCRIBE করতে পারো।
- শুভকামনায় ওয়েব স্কুল বিডি

Previous Post Next Post