Skip to content

Try our new Crash Courses!

Buy one of our new Crash Courses, now hosted on Teachable.

Inline script – JavaScript

Summary

To create an inline script, place your JavaScript code directly inside a script element:

<script>
  console.log("Test message");
</script>

Details

When writing JavaScript, you have the option of placing JavaScript code directly inside a script element in an HTML file. Please note, however, that this is generally not recommended. Inline scripts are acceptable for quick testing of JavaScript code, but the best practice is to store your JavaScript code in a separate JavaScript file.

Note that you do not need the src attribute when creating an inline script.

Demo

inline script demo

Exercises

Try recreating the code snippet from the lesson in the index.html file.

References

The Script element on MDN

Back to: JavaScript Reference > JS Introduction