Ads Top

Javascript questions and answers

Q1. What is the Javascript?
JavaScript is the client side as well as a server-side programming language.
This language is case-sensitive. Javascript only interpreted language. Also, follow the camel case coding conventions. We always terminate all code block from the semicolon (:).
Q2. What is the JavaScript Variable?
Javascript variable is a data storage area, It’s allocated on the RAM.

Q3. How many data type available in javascript?
Commonly in Javascript have five type data type –
As: String, Number, Boolean, null & undefined.
But nowadays we have added function, Array and Object.
Q4. What is the typecasting in Javascript?
Javascript have two type – type casting: one is the auto and second is the Manual. If we will not define data type in any variable then it will detect automatically. So it’s auto type casting. And if you will define data type in variable As:
var abc = Number(123);
var ab = String(‘Hello world!’);

Q5. What is the mean of interpreted Language?
Interpreted language means that it’s not transformed in the computer language (binary).
You can’t modify in transformed code so it’s good for the security purpose. If required the modification then need to the original code. But you can modify any project where is the depend on the Javascript based project because this is only interpreted language.

Q6. How to change data type of the variables in JavaScript?
This is so simple as javascript already define a method for the convert data type each as: String(), Number(), Boolean().
You can understand with this example:
var abc = 123;
it will change var ab = String(abc);

Q7.  How to create table code in javaScript?

This code for the single table generation: Looks Like
.............................................................

<style>

        ul#outPut {

            list-style: none;

        }

    </style>

    <div>

        <input type="text" id="inputBox"> <input type="button" value="Generate Table" onclick="tables()">

        <ul id="outPut"></ul>

    </div>


    <script>
        function tables() {
            var tabs = document.getElementById('inputBox').value;
            var txt = '';
            for (var i = 1; i < 10; i++) {
                txt += '<li>' + i * tabs + '</li>';
            }
            document.getElementById('outPut').innerHTML = txt;
        }
    </script>
.............................................................

This code for the "from start count to end count" table generation: 
...................................................................

<style>
        #outPut ul {
            list-style: none;
            display: inline-block;
            padding: 0;
            margin: 10px;
            margin-left: 0;
        }

        #outPut ul li {
            border: 1px solid #ccc;
            padding: 5px;
        }
    </style>
    <div>
        <input type="text" id="inputBox1" placeholder="Strat From"><input type="text" id="inputBox2" placeholder="End table count">        <input
            type="button" value="Generate Table" onclick="tablesMulti()">
        <div id="outPut">

        </div>
    </div>

    <script> 
        function tablesMulti() {
            var fTabs = document.getElementById('inputBox1').value;
            var sTabs = document.getElementById('inputBox2').value;
            var ss = '';
            for (var i = fTabs; i <= sTabs; i++) {
                var text = '<ul>';
                for (var j = 1; j <= 10; j++) {
                    text += '<li>' + i + 'x' + j + ' = <strong>' + i * j + '</strong></li>';
                }
                var text = text + '</ul>';
                ss += text;
                document.getElementById('outPut').innerHTML = ss;
            }
        }
    </script>
......................................................................................................................................
  
Q8. Add edit delete in JavaScript? 

Code demo
......................................................................................................................

<script>



        var stuDataArr = [];

        var editID = '';



        function stuSave() {
            var stName = document.getElementById('stuName').value;
            var stRoll = document.getElementById('stuRoll').value;
            var stCont = document.getElementById('stuCont').value;

            var rowObjec = {
                name: stName,
                roll: stRoll,
                contact: stCont
            }

            stuDataArr.push(rowObjec);

            document.getElementById('stuName').value = '';
            document.getElementById('stuRoll').value = '';
            document.getElementById('stuCont').value = '';
        }

        function showData() {
            var text = '';
            for (var i = 0; i <= stuDataArr.length - 1; i++) {
                text += '<tr>';
                text += '<td>' + stuDataArr[i].name + '</td>';
                text += '<td>' + stuDataArr[i].roll + '</td>';
                text += '<td>' + stuDataArr[i].contact + '</td>';
                text += '<td><button onclick="Edit(' + [i] + ')">Edit</button><button onclick="Delete(' + [i] + ')">Delete</button></td>';
                text += '</tr>';
            }
            document.getElementById('showDataContainer').innerHTML = text;
           
        }

        function Delete(val) {
            stuDataArr.splice(val, 1);
            showData();
        }

        function Edit(val) {
            editID = val;
            document.getElementById('stuName').value = stuDataArr[editID].name;
            document.getElementById('stuRoll').value = stuDataArr[editID].roll;
            document.getElementById('stuCont').value = stuDataArr[editID].contact;

            document.getElementById('stuSaveId').style = 'display:none;';
            document.getElementById('stuUpdateId').style = 'display:inline-block;';
        }

        function stuUpdate() {
            stuDataArr[editID].name = document.getElementById('stuName').value;
            stuDataArr[editID].roll = document.getElementById('stuRoll').value;
            stuDataArr[editID].contact = document.getElementById('stuCont').value;

            document.getElementById('stuName').value = '';
            document.getElementById('stuRoll').value = '';
            document.getElementById('stuCont').value = '';

            document.getElementById('stuSaveId').style = 'display:inline-block;';
            document.getElementById('stuUpdateId').style = 'display:none;';

            showData();
        }

        function stuSearchData() {
            var searchd = document.getElementById('stuSearchId').value;

            var text = '';
            for (var i = 0; i <= stuDataArr.length - 1; i++) {
                if (stuDataArr[i].name === searchd || stuDataArr[i].roll === searchd || stuDataArr[i].contact === searchd) {
                    text += '<tr>';
                    text += '<td>' + stuDataArr[i].name + '</td>';
                    text += '<td>' + stuDataArr[i].roll + '</td>';
                    text += '<td>' + stuDataArr[i].contact + '</td>';
                    text += '<td><button onclick="Edit(' + [i] + ')">Edit</button><button onclick="Delete(' + [i] + ')">Delete</button></td>';
                    text += '</tr>';
                }
                document.getElementById('showDataContainer').innerHTML = text;
            }
        }

    </script>



<div>
        <input type="text" id="stuName" placeholder="Student Name">
        <input type="text" id="stuRoll" placeholder="Student Roll Number">
        <input type="text" id="stuCont" placeholder="Student Contact">
        <button id="stuSaveId" onclick="stuSave()">Save</button>
        <button id="stuUpdateId" onclick="stuUpdate()" style="display:none;">Update</button>
    </div>
    <br><br>
    <input type="text" id="stuSearchId" placeholder="Search"><button onclick="stuSearchData()">Search</button>
    <br><br>
    <button onclick="showData()">Show Data</button>
    <br><br>
    <table border="1">
        <thead>
            <tr>
                <th>Name</th>
                <th>Roll Number</th>
                <th>Contact Number</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody id="showDataContainer">

        </tbody>
    </table>
 
......................................................................................................................



Q9. How to create new object in javascript?

Q10. How to access value in javascript?

Q11. How to create pagination in javascript?

Q12. What is the prototype in javascript?

Q13. What is web worker in javascript?

Q14. What is callback function in javascript?


No comments:

Copyright Reserved to Anything Learn. Powered by Blogger.