Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is a JavaScript pragma?

Tags:

javascript

When you want a JavaScript file (or function) to be parsed in "strict mode" you can put..

"use strict";

..in the top of your JavaScript file (or function).

This "use strict"; is a so-called "pragma".

My question: what exactly is a pragma? The closest thing I can think of is a "directive".

like image 853
Niels Bom Avatar asked Jan 29 '13 22:01

Niels Bom


People also ask

What does pragma stand for?

Pragma is short for pragmatic information. So, simple. In plain English, pragmatic is an adjective that means sensible and practical.

Why is it called pragma?

The term pragmatism is derived from the Greek word pragma - πράγμα, meaning action, from which the words 'practice' and 'practical' come.

What are pragma statements?

The PRAGMA statement is an SQL extension specific to SQLite and used to modify the operation of the SQLite library or to query the SQLite library for internal (non-table) data.


1 Answers

compiler directives are called pragmas (short for "pragmatic information").

http://en.wikipedia.org/wiki/Preprocessor_directive

It's a pre-processor directive, or like code metadata. It's similar to other languages or compilers that use stuff like this more. It's pragmatic information about how to interpret the code that follows.

And as far as I know, this is the only one in JavaScript. It's sort of a hack to force modern interpreters to behave in a certain way, but without breaking older interpreters.

like image 186
Alex Wayne Avatar answered Oct 03 '22 13:10

Alex Wayne