Run a.js file

Asked

Viewed 15,259 times

0

I am doing a JS course and created a.js file on var/www/html/js/index.js. But when I try to run the file in the browser http://localhost/js/index.js it does not run ! It just shows the code I wrote in the browser.

This is my file:

function Person() {
    this.name = '';
    this.age = '';
    this.eyesColor = '';
    this.body = '';

    this.move = function() {
        //
    }

    this.say = function() {
        //      
    }

    this.see = function() {
        //      
    }

}

var lucas = new Person();

console.log(typeof Person());
console.log(typeof lucas);

1 answer

2


Directly accessing a Javascript file (.js) does not cause it to run. You can create an HTML page and include the path to your script.

Ex:

<script src="index.js"></script>

You can also run straight in the browser console, key F12 in Chrome.

It is also possible to add directly on the page, just create the tag <script> and put the content inside it. Ex:

<script>
function Person() {
    this.name = '';
    this.age = '';
    this.eyesColor = '';
    this.body = '';

    this.move = function() {
        //
    }

    this.say = function() {
        //      
    }

    this.see = function() {
        //      
    }

}

var lucas = new Person();

console.log(typeof Person());
console.log(typeof lucas);
</script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.