1. Question:How to use ternary operator in JavaScript? 

    Answer
    The ternary(?) operator can be used as a shortcut for an if....else statement. It is typically used as part of a larger expression where an if...else statement would be awkward. For example:
    var now = new Date();
    var greeting = "Good" + ((now.getHours() > 17) ? " evening." : " day.");
    The example creates a string containing "Good evening." if it is after 6pm.

    1. Report
  2. Question:What is escape sequence? How to use it? 

    Answer
    Escape sequence is a way to include escape characters and sequences for additional control over string literals. It is written by prefacing a code with a backslash(\). For example, the literal \' prints an apostrophe without affecting the literal itself.

    1. Report
  3. Question:What are Data Types in JavaScript? 

    Answer
    In JavaScript Data types are divided into two basic categories, primitive and compound.Primitive Data Types:Boolean values, numbers, strings, and the null and undefined values all constitute primitive data types.Compound Data Types: Compound data types are made of more than one components. Two primitive data types, such as 10 multiplied by 7, can make up compound data.

    1. Report
  4. Question:What is eval() in javaScript? 

    Answer
    The eval() function evaluates or executes an argument.If the argument is an expression, eval() evaluates the expression. If the argument is one or more JavaScript statements, eval() executes the statements.
    var x = 10;
    var y = 20;
    var a = eval("x*y") + "<br>";
    var b = eval("2+2") + "<br>";
    var c = eval("x+17") + "<br>";
    
    var res = a + b + c;
    The result of res will be 200 4 27

    1. Report
  5. Question:Define concatenation. 

    Answer
    The concatenation is a process to join two or more strings or strings and other literals.Generally '+' is used to concatenate strings.
    For Example:
    var str=("Bangla"+"desh")
    output:Bangladesh

    1. Report
  6. Question:Why is Objected Oriented Programming? 

    Answer
    1. For working with more people on web project using javaScript and the scripts become longer,OOP becomes more important.
    2.Because OOP encourages modular program units, the units can be shared with others on a programming team and can be reused.

    1. Report
  7. Question:What is Operator Precedence? 

    Answer
    The order in which expressions are evaluated based on their operators is known as precedence. For example, multiplication and division occur before addition and subtraction, so any operands that are to be multiplied or divided occur before ones that are added and subtracted.

    1. Report
  8. Question:Briefly describe the new, delete and void operators

    Answer
    New operator:All objects must begin with a constructor preceded by the new operator.
    Example:
    var family=new Array("Dad","Mom","Sue","Kris");
    Delete operator:The delete operator removes an object property or an array element in a script. Example:
    var family=new Array("Dad","Mom","Sue","Kris");
    delete family[2];
    Void Operator:Void operator is unary and operates on any literal or variable.Usually, we will see this operator as part of an <A> tag in an HTML script. Example:
    <a href="javascript:void(0)" onClick="scroll(500,0)">

    1. Report
  9. Question:Define a function to sum up any number of numbers. 

    Answer
    <script>
            function add(...numbers){
                 
              let total=0;
              for(let n of numbers){
                  total+=n;
              }
                 return total;
            }
    
            document.write(add(3,4,3,5,7,3,23,7));
        </script>

    1. Report
Copyright © 2024. Powered by Intellect Software Ltd